Friz lanz
Friz lanz

Reputation: 48

Blackberry - get image data from bitmap

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();

Upvotes: 0

Views: 795

Answers (1)

Onuray Sahin
Onuray Sahin

Reputation: 4135

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);

Upvotes: 1

Related Questions