当前位置: 首页 > 工具软件 > Jimi > 使用案例 >

java用jimi.jar实现图片格式转换

邵正雅
2023-12-01

1.导入jimi.jar

 

2.将gif图片转换成jpg格式

public static void toJPG() {

  try {
   String source = "d:/1.gif";
   String dest = source.substring(0, source.lastIndexOf(".")) + ".jpg";
   System.out.println(dest);

   JPGOptions options = new JPGOptions();
   options.setQuality(72);
   ImageProducer image = Jimi.getImageProducer(source);
   JimiWriter writer = Jimi.createJimiWriter(dest);
   writer.setSource(image);
   writer.setOptions(options);
   writer.putImage(dest);
  } catch (JimiException je) {
   System.err.println("Error: " + je);
  }
 }

 类似资料: