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
New Developer
ashihs_k
Posts: 31
Registered: ‎09-24-2008
My Device: Not Specified

Reduce size of image.

I have an bytearray of jpeg image.

i want to reduce the size of this amage.

actual  size of image is neer about 120kb.

 

i want to reduce it up to 60kb..

 

how this is possible..

 

plz help ...

 

Thanks in advance

Ashish k.

 

Please use plain text.
Developer
Posts: 5,339
Registered: ‎09-20-2008
My Device: ***
My Carrier: ***

Re: Reduce size of image.

reduce colors, resolution, dimensions.

 

attach your image file here - I'll check what can be done.

Please use plain text.
New Developer
ashihs_k
Posts: 31
Registered: ‎09-24-2008
My Device: Not Specified

Re: Reduce size of image.

Thanks for reply,

 

buta i have an bytearrai of image.

not the image file.

 

so have can ireduce the color of image.

Please use plain text.
Developer
Posts: 5,339
Registered: ‎09-20-2008
My Device: ***
My Carrier: ***

Re: Reduce size of image.

Check the API classes:

 

net.rim.device.api.compress.ZLibInputStream
net.rim.device.api.compress.ZLibOutputStream

 

They can help to compress/decompress your data.

 

JPEG data cannot be compressed with 50% ratio, so consider to reduce colors/dimensions of the original image.

Please use plain text.
Developer
simon_hain
Posts: 16,113
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Reduce size of image.

the bytearray is just another representation of the image, you can use the EncodedImage class to create an object. Use scaleImage32 to change it size, be aware of it using fixed32 ints.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Contributor
satyagrwl
Posts: 12
Registered: ‎06-16-2011
My Device: 9000
My Carrier: Vodafone

Re: Reduce size of image.

Hi Simon,

 

I tried by doing bellow, but EncodedImage.getBytes returning the origional bytes. Please suggest.

private static byte[] reduceImageDataSize(byte[] imageData) {
        long length = imageData.length;
        EncodedImage img = EncodedImage.createEncodedImage(imageData, 0, imageData.length);
        int width = img.getWidth();
        int height = img.getHeight();
        int reqWidth = (int) (width / 2);
        int reqHeight = (int) (height / 2);
        img = ImageUtills.rescaleImage(img, reqWidth, reqHeight);
        imageData = img.getData();
        return imageData;
    }

Please use plain text.
New Member
gdiekirch
Posts: 2
Registered: ‎03-06-2013
My Device: Bold
My Carrier: Peruz

Re: Reduce size of image.

you can try some other solutions as well, like Graphics2D.scale and Image.getScaledInstance. I've used them in the past, but can't remember which had better performance or better looking results, sorry

Please use plain text.
Contributor
satyagrwl
Posts: 12
Registered: ‎06-16-2011
My Device: 9000
My Carrier: Vodafone

Re: Reduce size of image.

Hi gdiekirch,

 

Thanks for reply but thease both classes from java.awt which is not avaibale in blackberry API set.

Can you please suggest how you acheived this in blackberry.

 

Thanks,

Satya

Please use plain text.