Int像素阵列到图像

时间:2014-10-23 20:51:33

标签: java android arrays bitmap bufferedimage

我正在尝试从Android上的Bitmap获取一个int数组像素,并使用int数组来制作缓冲图像。但是我遇到了一些问题。我能够从android获取位图没有问题:

Bitmap b = BitmapFactory.decodeByteArray(data, 0, data.length);
b = Bitmap.createScaledBitmap(b, (int)(b.getWidth() * .3125), (int)(b.getHeight() * .44444444444), false);
int[] arr = new int[b.getHeight() * b.getWidth()];
b.getPixels(arr, 0, b.getWidth(), 0, 0, b.getWidth(), b.getHeight());

我向下缩放位图然后获取像素并将它们放入int数组中。然后我通过网络将它们发送到PC,我尝试将其重新创建为BufferedImage(网络并不重要)。这是我用来将像素数组转换为BufferedImage的代码。

int width = 600;
int height = 479;

BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
bi.setRGB(0, 0, width, height, arr, 0, width);
g2d.drawImage(bi, 10, 50, null);

变量" arr"是像素的字节数组。转换为BufferedImage不会出现错误,并显示以下图像:enter image description here

显然,这不是我想要获得的图片。当我打印出阵列中的5个像素(仅用于测试)时,我得到以下内容,这是像素的格式:

-15528956
-15200766
-13558523
-11718123
-12243954
-13294582

0 个答案:

没有答案