当前位置:   article > 正文

java图片格式转化(例如jpg格式转化png)_zpl转png java

zpl转png java

转载自  java图片格式转化(例如jpg格式转化png)

  1. import java.awt.image.BufferedImage;
  2. import java.io.File;
  3. import java.io.IOException;
  4. import java.util.Scanner;
  5. import javax.imageio.*;
  6. public class FormatConversion {
  7.     public static final String JPG = "jpg";
  8.     public static final String GIF = "gif";
  9.     public static final String PNG = "png";
  10.     public static final String BMP = "bmp";
  11.     public static void main(String[] args) {
  12.         String src = "E:/2.";
  13.         new FormatConversion().Conversion(JPG,PNG,src);//JPG转成PNG
  14.         new FormatConversion().Conversion(JPG,GIF,src);//JPG转成GIF
  15.         new FormatConversion().Conversion(JPG,BMP,src);//JPG转成BMP
  16.         //其余格式转化只要调用Conversion函数即可
  17.     }
  18.     //inputFormat表示原格式,outputFormat表示转化后的格式
  19.     public void Conversion(String inputFormat,String outputFormat,String src){
  20.         try {
  21.             File input = new File(src+inputFormat);
  22.             BufferedImage bim = ImageIO.read(input);
  23.             File output = new File(src+outputFormat);
  24.             ImageIO.write(bim, outputFormat, output);
  25.         } catch (IOException e) {
  26.             e.printStackTrace();
  27.         }
  28.     }
  29. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/不正经/article/detail/715972
推荐阅读
相关标签
  

闽ICP备14008679号