黑莓 - 从位图获取图像数据

时间:2011-07-11 13:42:27

标签: image blackberry java-me

如何从位图图像中获取图像数据?我搜索了,但我找不到解决方案

int height=bmp.getHeight();

int width=bmp.getWidth();
int[] rgbdata = new int[width*height];
ByteArrayOutputStream bos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(bos);
//Graphics g = new Graphics(bmp);
bmp.getARGB(rgbdata,0,width,0,0,width,height);

for (int i = 0; i < rgbdata.length ; i++) {
    if (rgbdata[i] != -1)
    {
        dos.writeInt(rgbdata[i]);
        dos.flush();
    }
} 
bos.flush();

1 个答案:

答案 0 :(得分:1)

试试这个:

PNGEncoder encoder = new PNGEncoder(bitmap, true);
byte[] imageBytes = encoder.encode(true);

从字节数组中获取EncodedImage:

EncodedImage fullImage = EncodedImage.createEncodedImage(imageBytes, 0, imageBytes.length);