Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Contributor
Posts: 10
Registered: ‎05-25-2011
My Device: Torch 9800
My Carrier: Rogers
Accepted Solution

image compression and conversion between Bitmap and byte[]

[ Edited ]

Hi,

I'm trying to compress a raw image data(byte[]), and here is what I did:

Bitmap image = Bitmap.createBitmapFromBytes( _raw, 0, -1, 7 );
Bitmap scaledBitmap = new Bitmap(192, 144);
image.scaleInto(scaledBitmap, Bitmap.FILTER_BILINEAR, Bitmap.SCALE_TO_FIT);

 So now I have a compressed Bitmap, scaledBitmap, and I want to extract the raw data(byte[]) from the scaledBitmap. I noticed there is a method getRGB565, but I'm not sure how to use it. Can someone give me an example about how to extract the raw data? If it's not possible, is there an alternative way to compress the _raw?

Thanks in advance.

Contributor
Posts: 10
Registered: ‎05-25-2011
My Device: Torch 9800
My Carrier: Rogers

Re: image compression and conversion between Bitmap and byte[]

I found the solution:

Bitmap image = Bitmap.createBitmapFromBytes( _raw, 0, -1, 8 );
          
int newWidth = 192;
int newHeight = 144;
        
Bitmap scaledBitmap = new Bitmap(newWidth, newHeight);
image.scaleInto(scaledBitmap, Bitmap.FILTER_BILINEAR, Bitmap.SCALE_TO_FIT);
PNGEncodedImage encoder = PNGEncodedImage.encode(scaledBitmap);
byte[] resizedBytes = encoder.getData();