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
Developer
roney99625
Posts: 39
Registered: ‎03-20-2009
My Device: Not Specified

Resizing bitmap without creating encoded image

Hi,

 

Can any one tell me how to resize a bitmap without creating encoded image from it? When I create encoded image from bitmap and try to resize it, the hour glass displayed all the times. I want to get rid of that. Please advice.

 

Regards,

Roney

Please use plain text.
Developer
cagdasgerede
Posts: 241
Registered: ‎11-20-2008
My Device: Not Specified

Re: Resizing bitmap without creating encoded image

I asked the same question in the following thread: 

http://supportforums.blackberry.com/rim/board/message?board.id=java_dev&message.id=27408#M27408

 

Unfortunately there is no other way to resize a bitmap without creating an encoded image (as of 4.7). In my case, the performance was not so bad. How big is your bitmap? Do you specify the scale parameters correctly (see the thread for an example)?

 

I ran this in Bold. Which device are you using? Is this a bitmap that is part of the project (static image) or it is something that you receive at run time over the network? If you provide more information I can try to give more useful suggestions.

 

 

 

 

 

Please use plain text.
Developer
bikas
Posts: 984
Registered: ‎02-10-2009
My Device: Not Specified

Re: Resizing bitmap without creating encoded image

[ Edited ]

Try this:

 

public static Bitmap resizeBitmap(Bitmap image, int width, int height)
{
int imageWidth = image.getWidth();
int imageHeight = image.getHeight();

// Need an array (for RGB, with the size of original image)
int rgb[] = new int[imageWidth * imageHeight];

// Get the RGB array of image into "rgb"
image.getARGB(rgb, 0, imageWidth, 0, 0, imageWidth, imageHeight);

// Call to our function and obtain rgb2
int rgb2[] = rescaleArray(rgb, imageWidth, imageHeight, width, height);

// Create an image with that RGB array
Bitmap temp2 = new Bitmap(width, height);

temp2.setARGB(rgb2, 0, width, 0, 0, width, height);

return temp2;
}

 

private static int[] rescaleArray(int[] ini, int x, int y, int x2, int y2)
{
int out[] = new int[x2*y2];
for (int yy = 0; yy < y2; yy++)
{
int dy = yy * y / y2;
for (int xx = 0; xx < x2; xx++)
{
int dx = xx * x / x2;
out[(x2 * yy) + xx] = ini[(x * dy) + dx];
}
}
return out;
}  

 

 

Regards

Bikas

  

 

Message Edited by bikas on 06-26-2009 01:08 PM
Please use plain text.
Developer
cagdasgerede
Posts: 241
Registered: ‎11-20-2008
My Device: Not Specified

Re: Resizing bitmap without creating encoded image

Well, I should correct myself. When I said there is no other way, I meant there is no other built-in way. If you would like to process an argb array yourself, then you apply any scaling algorithm you want. I haven't benchmarked processing an argb array, because I assumed that looping like this over a large array would be slow. If you apply this technique, I appreciate if you can share how it performs (or may be bikas can do).

 

 

Please use plain text.
Developer
bikas
Posts: 984
Registered: ‎02-10-2009
My Device: Not Specified

Re: Resizing bitmap without creating encoded image

Hi cagdasgerede,

 

Yes its a bit slow than scaling an image using Encoded image.

But i think it will give better scaled image than scale using encoded image.

 

I think sometime you have to sacrifice some performance penalty for quality.


Regards

Bikas

Please use plain text.
Developer
roney99625
Posts: 39
Registered: ‎03-20-2009
My Device: Not Specified

Re: Resizing bitmap without creating encoded image

Thanks Bikas & cagdasgerede,

 

But my problem here is the performance and not quality. I am receiving image data over network and I have to resize it (both then way, means up scale and down scale). I am having trouble with encode + resize oprations since it resuluts in a hour glass display and dumping GC messages on console.

 

Regards,

Roney

Please use plain text.
Developer
cagdasgerede
Posts: 241
Registered: ‎11-20-2008
My Device: Not Specified

Re: Resizing bitmap without creating encoded image

What is your phone model?

 
How big are your bitmaps? and To what sizes are you scaling up and down?

Please use plain text.
Developer
roney99625
Posts: 39
Registered: ‎03-20-2009
My Device: Not Specified

Re: Resizing bitmap without creating encoded image

The phone model is BB Bold 9000. bitmap is of 320 x 480 and trying to resize it something around 616 x 919.
Please use plain text.
Developer
cagdasgerede
Posts: 241
Registered: ‎11-20-2008
My Device: Not Specified

Re: Resizing bitmap without creating encoded image

Are you trying to zoom in?

why do you need a bitmap bigger than your screen size?

 

 

Please use plain text.
Developer
roney99625
Posts: 39
Registered: ‎03-20-2009
My Device: Not Specified

Re: Resizing bitmap without creating encoded image

It is a project requirement!!!
Please use plain text.