1. <ul id="0c1fb"></ul>

      <noscript id="0c1fb"><video id="0c1fb"></video></noscript>
      <noscript id="0c1fb"><listing id="0c1fb"><thead id="0c1fb"></thead></listing></noscript>

      99热在线精品一区二区三区_国产伦精品一区二区三区女破破_亚洲一区二区三区无码_精品国产欧美日韩另类一区

      RELATEED CONSULTING
      相關咨詢
      選擇下列產(chǎn)品馬上在線溝通
      服務時間:8:30-17:00
      你可能遇到了下面的問題
      關閉右側(cè)工具欄

      新聞中心

      這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
      怎么在Java項目中將gif圖片轉(zhuǎn)換為jpg格式

      這篇文章主要介紹了怎么在Java項目中將gif圖片轉(zhuǎn)換為jpg格式,此處給大家介紹的非常詳細,對大家的學習或工作具有一定的參考價值,需要的朋友可以參考下:

      成都一家集口碑和實力的網(wǎng)站建設服務商,擁有專業(yè)的企業(yè)建站團隊和靠譜的建站技術(shù),10多年企業(yè)及個人網(wǎng)站建設經(jīng)驗 ,為成都上1000+客戶提供網(wǎng)頁設計制作,網(wǎng)站開發(fā),企業(yè)網(wǎng)站制作建設等服務,包括成都營銷型網(wǎng)站建設,品牌網(wǎng)站設計,同時也為不同行業(yè)的客戶提供做網(wǎng)站、成都網(wǎng)站制作的服務,包括成都電商型網(wǎng)站制作建設,裝修行業(yè)網(wǎng)站制作建設,傳統(tǒng)機械行業(yè)網(wǎng)站建設,傳統(tǒng)農(nóng)業(yè)行業(yè)網(wǎng)站制作建設。在成都做網(wǎng)站,選網(wǎng)站制作建設服務商就選創(chuàng)新互聯(lián)公司

      if(fileName.toLowerCase().endsWith(".gif")){//由于頭像上傳支持JPG、JPEG、BMP、GIF、PNG格式圖片.而商湯人臉設備僅支持JPG、JPEG、BMP、PNG,故如圖片為GIF格式需要轉(zhuǎn)換
         fileParams.put("avatarFile", api.GifToJpg(avatar_file));
       }else{
         fileParams.put("avatarFile", api.getBytes(avatar_file));
       }
      /**
        * 將文件轉(zhuǎn)換為byte二進制流
        * @param f
        * @return
        */
       public static byte[] getBytes(File f) {
        try {
         InputStream in = new FileInputStream(f);
         ByteArrayOutputStream out = new ByteArrayOutputStream(1024);
         byte[] b = new byte[1024];
         int n;
         while ((n = in.read(b)) != -1)
          out.write(b, 0, n);
         in.close();
         out.close();
         return out.toByteArray();
        } catch (IOException e) {
         logger.error("***請設置文件路徑***");
         e.printStackTrace();
        }
        return null;
       }
       /**
        * 將gif格式圖片轉(zhuǎn)換為jpg格式文件,并直接返回byte二進制流
        * @param file
        * @return
        */
       public static byte[] GifToJpg(File file){
        BufferedImage bufferedImage;
        ByteArrayOutputStream out = new ByteArrayOutputStream(1024);
        try {
         // read image file
         bufferedImage = ImageIO.read(file);
         // create a blank, RGB, same width and height, and a white
         BufferedImage newBufferedImage = new BufferedImage(
           bufferedImage.getWidth(), bufferedImage.getHeight(),
           BufferedImage.TYPE_INT_RGB);
         // TYPE_INT_RGB:創(chuàng)建一個RBG圖像,24位深度,成功將32位圖轉(zhuǎn)化成24位
         newBufferedImage.createGraphics().drawImage(bufferedImage, 0, 0,Color.WHITE, null);
         // write to jpeg file
         ImageIO.write(newBufferedImage, "jpg",out);//轉(zhuǎn)換輸出到二進制數(shù)組流
         //ImageIO.write(newBufferedImage, "jpg",new File("c:\\java.jpg"));//轉(zhuǎn)換輸出到文件
         return out.toByteArray();//二進制流
        } catch (IOException e) {
         logger.error("***GifToJpg方法報錯***");
         e.printStackTrace();
        }
        return null;
       }

      知識點擴展:

      用java將png圖片轉(zhuǎn)換成jpg格式的圖片

      import java.awt.Color;
      import java.awt.image.BufferedImage;
      import java.io.File;
      import java.io.IOException;
      import javax.imageio.ImageIO;
      public class ConvertImageFile {
       public static void main(String[] args) {
       BufferedImage bufferedImage;
       try {
        //read image file
        bufferedImage = ImageIO.read(new File("c:\\java.png"));
        // create a blank, RGB, same width and height, and a white background
        BufferedImage newBufferedImage = new BufferedImage(bufferedImage.getWidth(),
         bufferedImage.getHeight(), BufferedImage.TYPE_INT_RGB);
        //TYPE_INT_RGB:創(chuàng)建一個RBG圖像,24位深度,成功將32位圖轉(zhuǎn)化成24位
        newBufferedImage.createGraphics().drawImage(bufferedImage, 0, 0, Color.WHITE, null);
        // write to jpeg file
        ImageIO.write(newBufferedImage, "jpg", new File("c:\\java.jpg"));
        System.out.println("Done");
       } catch (IOException e) {
        e.printStackTrace();
       }
       }
      }

      到此這篇關于怎么在Java項目中將gif圖片轉(zhuǎn)換為jpg格式的文章就介紹到這了,更多相關的內(nèi)容請搜索創(chuàng)新互聯(lián)以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持創(chuàng)新互聯(lián)!


      文章標題:怎么在Java項目中將gif圖片轉(zhuǎn)換為jpg格式
      標題網(wǎng)址:http://www.ef60e0e.cn/article/pdcghs.html
      99热在线精品一区二区三区_国产伦精品一区二区三区女破破_亚洲一区二区三区无码_精品国产欧美日韩另类一区
      1. <ul id="0c1fb"></ul>

        <noscript id="0c1fb"><video id="0c1fb"></video></noscript>
        <noscript id="0c1fb"><listing id="0c1fb"><thead id="0c1fb"></thead></listing></noscript>

        常州市| 简阳市| 崇文区| 柳河县| 博爱县| 思南县| 南涧| 绍兴市| 广饶县| 永春县| 天柱县| 鄄城县| 乐亭县| 平谷区| 泊头市| 民和| 利辛县| 慈利县| 肥东县| 定西市| 偏关县| 子洲县| 南汇区| 比如县| 调兵山市| 缙云县| 淅川县| 尉氏县| 哈密市| 定南县| 奈曼旗| 辉县市| 察雅县| 克拉玛依市| 高雄县| 锡林郭勒盟| 广丰县| 庄河市| 维西| 新河县| 朔州市|