[英]Java convert GIF image to PNG format
I have to build a Java servlet that receives an image and returns that image converted to PNG format. 我必须构建一个接收图像的Java servlet,并返回转换为PNG格式的图像。 How can I achieve this? 我怎样才能做到这一点? By converting I don't mean changing the file extension, like some examples suggest. 通过转换,我并不是说改变文件扩展名,就像一些例子所示。
Thanks in advance! 提前致谢!
Try this out: 试试这个:
package demo;
import javax.imageio.ImageIO;
import java.io.File;
import java.io.IOException;
public class Main {
public static void main( String [] args ) throws IOException {
File input = new File("input.gif");
File output = new File("output.png");
ImageIO.write( ImageIO.read( input ), "png", ouput);
}
}
Of course, you may want to read and write from an stream instead. 当然,您可能希望从流中读取和写入。
ImageIO.write(ImageIO.read(new File("img.gif")), "png", new File("img.png"));
使用ImageIo以您想要的任何格式保存图像。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.