2012-05-23 81 views
1

我们知道,我们可以得到位图图像的RGB使用的代码如下:转换阵列为位图

BufferedImage img = ImageIO.read(new File(bitmapURL)); 
int[] pixels = img.getRGB(0, 0, img.getWidth(), img.getHeight(), null, 0, img.getWidth()); 

而且,执行的代码,这部分后,我们有一个整数数组其中包含任何像素的Alpha, Red, Green and Blue颜色的4个字节。所以,我想知道如何将像int [] myPixels;这样的整数数组转换为位图?任何人都可以帮助我达成这个目标吗?

感谢提前:)

回答

4

您可以直接使用此:

image.setRGB(0, 0, width, height, pixels, 0, width); 

Source

0

BufferedImage im = new BufferedImage(width, height); 

for (int i = 0; i < width; i++) { 
    for (int j = 0; j < height; j++) { 
    im.setRGB(...); 
    } 
} 
 
+0

请注意,我们有一个一维数组,而不是二维数组!那么,我该如何将其转换为位图? –

+0

是的,你需要为你设置的像素计算阵列中正确的偏移量 – ControlAltDel

+0

然后你应该用'for(int i = 0; i StepTNT