Java converts GIF image to PNG format

I need to create a Java servlet that receives an image and returns that image converted to PNG format. How can i achieve this? When converting, I do not mean changing the file extension, as some examples show.

Thanks in advance!

+6
java png gif
source share
3 answers

Try the following:

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); } } 

Read ImageIO .

Of course, you can read and write from the stream.

+14
source share
 ImageIO.write(ImageIO.read(new File("img.gif")), "png", new File("img.png")); 
+5
source share

Use ImageIo to save the image in any format you want.

+2
source share

All Articles