BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 07-22-2008, 09:54 AM   #1 (permalink)
Talking BlackBerry Encyclopedia
 
Join Date: Jan 2008
Location: France
Model: 8310
PIN: N/A
Carrier: Vodafone
Posts: 217
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default Resize a bitmap

Please Login to Remove!

Hi everyone,

I'd like to know how can I change the size of a bitmap.

For example I create a Bitmap like this :

Bitmap bmp = new Bitmap(40,40);

Then I want to recover a bitmapfield so :

BitMapField picture = new BitmapField(bmp.getBitmapResource("Picture.PNG"));

But I have a bitmapfield with the size of the Picture.PNG and not as I chose before.

What is the way to resize as I want???
Offline  
Old 07-22-2008, 02:25 PM   #2 (permalink)
Knows Where the Search Button Is
 
Join Date: May 2008
Model: 8310
PIN: N/A
Carrier: ATT
Posts: 17
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

You can use net.rim.device.api.system.EncodedImage class to scale down an image

Code:
EncodedImage ei = EncodedImage.getEncodedImageResource("image.png");   
ei.setScale(2); //half the size   
BitmapField bmp = new BitmapField(ei.getBitmap());   
add(bmp);
But I don't think this class supports resizing to any arbitrarly size. The only other way I can think of is overriding the paint() method of the BitmapField class and then using Graphics.drawBitmap... Well, other than using photoshop
Offline  
Old 07-22-2008, 02:56 PM   #3 (permalink)
Thumbs Must Hurt
 
Join Date: Dec 2005
Model: 8310
Carrier: Rogers
Posts: 138
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

use scaleImage32 to set it to an arbitrary size
Offline  
Old 07-23-2008, 03:49 AM   #4 (permalink)
Talking BlackBerry Encyclopedia
 
Join Date: Jan 2008
Location: France
Model: 8310
PIN: N/A
Carrier: Vodafone
Posts: 217
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks but as I don't want to lose the size's scale I will use setScale.
Offline  
Old 07-23-2008, 05:03 AM   #5 (permalink)
Talking BlackBerry Encyclopedia
 
Join Date: Jan 2008
Location: France
Model: 8310
PIN: N/A
Carrier: Vodafone
Posts: 217
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hum in fact my picture is on the web and I recover a bitmap from the url.

And as I see on the API, the EncodedImage doesn't take a bitmap in entry, does it???
Offline  
Old 07-23-2008, 05:44 AM   #6 (permalink)
Talking BlackBerry Encyclopedia
 
Join Date: Jan 2008
Location: France
Model: 8310
PIN: N/A
Carrier: Vodafone
Posts: 217
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hum allright I just find.

In fact my function recovering the bitmap use byte[] and EncodedImage.

So I just create a function that return the encodedImage instead of a bitmap
Offline  
Old 07-23-2008, 09:11 AM   #7 (permalink)
Talking BlackBerry Encyclopedia
 
Join Date: Jan 2008
Location: France
Model: 8310
PIN: N/A
Carrier: Vodafone
Posts: 217
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hum I like to have some explanation about the setScale.

Code:
EncodedImage emgphoto = maptmp.getImage(link);
int heightemg = emgphoto.getHeight();
int widthemg = emgphoto.getWidth();
while(heightemg > 50 && widthemg > 50)
{
    emgphoto.setScale(2);
    heightemg = emgphoto.getHeight();
    widthemg = emgphoto.getWidth();
}
Here I have an infinite loop.

I will check the heightemg and the widthemg
Offline  
Old 07-23-2008, 09:16 AM   #8 (permalink)
Talking BlackBerry Encyclopedia
 
Join Date: Jan 2008
Location: France
Model: 8310
PIN: N/A
Carrier: Vodafone
Posts: 217
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

After checking, my two variables never change.

What is wrong???
Offline  
Old 07-23-2008, 09:18 AM   #9 (permalink)
Talking BlackBerry Encyclopedia
 
Join Date: Apr 2008
Location: Germany, BW
Model: -
PIN: N/A
Carrier: -
Posts: 310
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

setScale() sets only the scale factor. The scaling itself will be done when calling getBitmap().
Offline  
Old 07-23-2008, 09:29 AM   #10 (permalink)
Talking BlackBerry Encyclopedia
 
Join Date: Jan 2008
Location: France
Model: 8310
PIN: N/A
Carrier: Vodafone
Posts: 217
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hum but as the encoded Image I will recover hasn't a size define I have to make more test.

But I think I see.

Thanks all for your answer.
Offline  
Old 07-23-2008, 09:34 AM   #11 (permalink)
Talking BlackBerry Encyclopedia
 
Join Date: Jan 2008
Location: France
Model: 8310
PIN: N/A
Carrier: Vodafone
Posts: 217
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

So I show my solution if someone needs it
Code:
int heightemg = emgphoto.getHeight();
int widthemg = emgphoto.getWidth();
int comp = 1;
while(heightemg > 50 && widthemg > 50)
{
    comp++;
    heightemg = heightemg / 2;
    widthemg = widthemg / 2;
}
emgphoto.setScale(comp);
Offline  
Old 07-24-2008, 03:25 AM   #12 (permalink)
Talking BlackBerry Encyclopedia
 
Join Date: Jan 2008
Location: France
Model: 8310
PIN: N/A
Carrier: Vodafone
Posts: 217
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

erratum.

My code is wrong ont the comp.

The correct line is :

comp = comp * 2;
Offline  
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





Copyright 2004-2014 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.