Search This Blog

Java: Convert image to png format

  • Make sure you have JAI & ImageIO plugins installed. Recommend to use standlone/independent jai-imageio-core from github.
  • The example code:
    • import java.awt.image.BufferedImage;
      import java.io.File;
      import javax.imageio.ImageIO;
      
      public static void main(String[] args) {
      
        ImageIO.scanForPlugins();
      
        // read a tiff image
        BufferedImage bufferedImage = ImageIO.read(new File("c:/tmp/1.tif"));
      
        // write back to another file in png format
        ImageIO.write(bufferedImage, "png", new File("c:/tmp/1.png"));
      
      }
      

No comments:

Post a Comment