Example #1
0
 /**
  * Save an array of ARGB pixels to a PNG file. If flipY is true, flip the pixels on the Y axis
  * before saving.
  */
 public static void savePixelsToPNG(
     int[] pixels, int width, int height, String imageFilename, boolean flipY) {
   if (pixels != null && imageFilename != null) {
     if (flipY) {
       // flip the pixels vertically (opengl has 0,0 at lower left, java is upper left)
       pixels = GLImage.flipPixels(pixels, width, height);
     }
     try {
       // Create a BufferedImage with the RGB pixels then save as PNG
       BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
       image.setRGB(0, 0, width, height, pixels, 0, width);
       javax.imageio.ImageIO.write(image, "png", new File(imageFilename));
     } catch (Exception e) {
       GLApp.err("GLImage.savePixelsToPNG(" + imageFilename + "): exception " + e);
     }
   }
 }