reference:
http://forums-beta.sun.com/thread.jspa?messageID=2817931
http://www.particle.kth.se/~lindsey/JavaCourse/Book/Part1/Supplements/Chapter11/pixelHandling.html
My code passed testing:
private byte[] icon_image_RGBA = new byte[32 * 32 * 4];
private int[] icon_image_ARGB = new int[32 * 32 + 2];
//public int[] icon_
public int icon_size=0;
public int icon_offset=0;
public String image_str = "temp.jpeg";
private File imgage_file = new File(image_str);
private void convertRGBAtoARGB(int width, int height){
icon_image_ARGB[0] = width;
icon_image_ARGB[1] = height;
/* Convert RGBA -> ARGB */
for (int i = 0; i < width * height; i++)
{
icon_image_ARGB[i + 2] =
icon_image_RGBA[i * 4 + 3] << 24 |
((icon_image_RGBA[i * 4 + 0] << 16) & 0x00FF0000) |
((icon_image_RGBA[i * 4 + 1] << 8) & 0x0000FF00) |
((icon_image_RGBA[i * 4 + 2] << 0) & 0x000000FF);
}
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
image.setRGB(0, 0, width, height, icon_image_ARGB, 0, width);
try {
ImageIO.write(image, "jpeg", imgage_file);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}