06-25-2009 09:50 PM
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
06-26-2009 02:04 AM
I asked the same question in the following thread:
http://supportforums.blackberry.com/rim/board/mess
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.
06-26-2009 02:27 AM - edited 06-26-2009 03:08 AM
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
06-26-2009 02:52 AM
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).
06-26-2009 03:13 AM
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
06-26-2009 02:34 PM
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
06-26-2009 02:39 PM
What is your phone model?
How big are your bitmaps? and To what sizes are you scaling up and down?
06-26-2009 03:26 PM
06-26-2009 06:57 PM
Are you trying to zoom in?
why do you need a bitmap bigger than your screen size?
07-09-2009 05:48 PM