import java.awt.Image;import java.awt.image.PixelGrabber;
import javax.imageio.ImageIO;
public class ImageConverter {
/** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub short [] pixels = parseImage("/ef1s.png"); } static class Rect{ public int _width; public int _height; public int [] _pixels; public Rect(int w, int h){ _width = w; _height = h; _pixels = new int[w * h]; } } public static short [] parseImage(String s){ Image image = null; try{ image = ImageIO.read("".getClass().getResourceAsStream(s)); } catch(Exception e){ } if(image == null) return null; int w = image.getWidth(null); int h = image.getHeight(null); if(w < 0 || h < 0) return null; Rect rect = new Rect(w, h); PixelGrabber pixelgrabber = new PixelGrabber(image, 0, 0, w, h, rect._pixels, 0, w); try { if(!pixelgrabber.grabPixels()) return null; } catch(InterruptedException interruptedexception1) { return null; } short [] results = new short[w * h]; int idx = 0; int idy = 0; int format = 4444; for(int l2 = 0; l2 < h; l2++) { if(format == 4444) { for(int i3 = 0; i3 < w; i3++) { int k3 = rect._pixels[idx++] >> 4 & 0xf0f0f0f; k3 = (k3 >> 4 | k3) & 0xff00ff; k3 = k3 >> 8 | k3; k3 &= 65535; results[idy++] = (short)k3; }
} else if(format == 565) { for(int j3 = 0; j3 < w; j3++) { int l3 = rect._pixels[idx++]; l3 = l3 >> 3 & 0x1f | l3 >> 5 & 0x7e0 | l3 >> 8 & 0xf800; results[idy++] = (short)l3; }
} else { throw new IllegalArgumentException(); } //i2 += l1 - k; //idy += rect._pixels.length - k; } return results; }
} |