Beispiel #1
0
 /**
  * Make a BufferedImage from the contents of an image file.
  *
  * @param imageFileContents byte array containing the guts of a JPG, GIF, or PNG
  */
 public BufferedImage makeBufferedImage(byte[] imageFileContents) {
   BufferedImage bi = null;
   try {
     InputStream in = new ByteArrayInputStream(imageFileContents);
     bi = javax.imageio.ImageIO.read(in);
   } catch (IOException ioe) {
     GLApp.err("GLImage.makeBufferedImage(): " + ioe);
   }
   return bi;
 }
Beispiel #2
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);
     }
   }
 }