开发者

java save jpg as png

I have an image on disk which is a jpg file . I want to convert and save it as png and delete original jpg. Whats best way to do this in java?

String justNameJpg = "so开发者_JAVA技巧mething.jpg";
String justNamePng = ImageEditor.GetImageNameNoExtension(justName) + "." + "png";
java.awt.image.BufferedImage bufferedImage = ImageIO.read(new File(folder, justNameJpg));
ImageIO.write(bufferedImage, "png", new File(folder, justNamePng));


If you want to use ImageIO this should work:

ImageIO.write(image, "png", new File("new output file name")); 


The best way is to call the external tool "imagemagick". This is no joke. I do it like that in my app, because it is much faster and more reliable than everything you get in Java.


imagemagick is a good option, from @Daniels answer. If you want to convert the thumbails in code, I had great luck with

http://code.google.com/p/thumbnailator/

it supports changing the file format for you, from the example page:

OutputStream os = ...;

Thumbnails.of("large-picture.jpg")
        .size(200, 200)
        .outputFormat("png")
        .toOutputStream(os);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜