Blackberry - get image data from bitmap

两盒软妹~` 提交于 2019-12-12 04:38:55

问题


how to get image data from a bitmap image ? i searched, but i cant find a solution

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:


Try this:

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

And to get EncodedImage from byte array:

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


来源:https://stackoverflow.com/questions/6650998/blackberry-get-image-data-from-bitmap

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!