Want more features on Pastebin? Sign Up, it's FREE!
Guest

Java2D_SpriteSheet

By: a guest on Nov 11th, 2012  |  syntax: None  |  size: 0.73 KB  |  views: 5  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. package j2dgame.gfx;
  2.  
  3. import java.awt.image.BufferedImage;
  4. import java.io.IOException;
  5.  
  6. import javax.imageio.ImageIO;
  7.  
  8. public class SpriteSheet {
  9.  
  10.         public String path;
  11.         public int width;
  12.         public int height;
  13.  
  14.         public int[] pixels;
  15.  
  16.         public SpriteSheet(String path) {
  17.                 BufferedImage image = null;
  18.  
  19.                 try {
  20.                         image = ImageIO.read(SpriteSheet.class.getResourceAsStream(path));
  21.                 } catch (IOException e) {
  22.                         e.printStackTrace();
  23.                 }
  24.  
  25.                 if (image == null) {
  26.                         return;
  27.                 }
  28.  
  29.                 this.path = path;
  30.                 this.width = image.getWidth();
  31.                 this.height = image.getHeight();
  32.  
  33.                 pixels = image.getRGB(0, 0, width, height, null, 0, width);
  34.                
  35.                 for(int i=0;i< pixels.length;i++){
  36.                         pixels[i]=(pixels[i] & 0xff)/64;
  37.                 }
  38.         }
  39.  
  40. }
clone this paste RAW Paste Data