BlackBerry Forums Support Community
              

Closed Thread
 
Thread Tools
Old 07-22-2008, 09:54 AM   #1
goulamass
Talking BlackBerry Encyclopedia
 
Join Date: Jan 2008
Location: France
Model: 8310
PIN: N/A
Carrier: Vodafone
Posts: 217
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
sajika
Knows Where the Search Button Is
 
Join Date: May 2008
Model: 8310
PIN: N/A
Carrier: ATT
Posts: 17
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
CELITE
Thumbs Must Hurt
 
Join Date: Dec 2005
Model: 8310
Carrier: Rogers
Posts: 138
Default

use scaleImage32 to set it to an arbitrary size
Offline  
Old 07-23-2008, 03:49 AM   #4
goulamass
Talking BlackBerry Encyclopedia
 
Join Date: Jan 2008
Location: France
Model: 8310
PIN: N/A
Carrier: Vodafone
Posts: 217
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
goulamass
Talking BlackBerry Encyclopedia
 
Join Date: Jan 2008
Location: France
Model: 8310
PIN: N/A
Carrier: Vodafone
Posts: 217
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
goulamass
Talking BlackBerry Encyclopedia
 
Join Date: Jan 2008
Location: France
Model: 8310
PIN: N/A
Carrier: Vodafone
Posts: 217
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
goulamass
Talking BlackBerry Encyclopedia
 
Join Date: Jan 2008
Location: France
Model: 8310
PIN: N/A
Carrier: Vodafone
Posts: 217
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
goulamass
Talking BlackBerry Encyclopedia
 
Join Date: Jan 2008
Location: France
Model: 8310
PIN: N/A
Carrier: Vodafone
Posts: 217
Default

After checking, my two variables never change.

What is wrong???
Offline  
Old 07-23-2008, 09:18 AM   #9
Ivanov
Talking BlackBerry Encyclopedia
 
Join Date: Apr 2008
Location: Germany, BW
Model: -
PIN: N/A
Carrier: -
Posts: 310
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
goulamass
Talking BlackBerry Encyclopedia
 
Join Date: Jan 2008
Location: France
Model: 8310
PIN: N/A
Carrier: Vodafone
Posts: 217
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
goulamass
Talking BlackBerry Encyclopedia
 
Join Date: Jan 2008
Location: France
Model: 8310
PIN: N/A
Carrier: Vodafone
Posts: 217
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
goulamass
Talking BlackBerry Encyclopedia
 
Join Date: Jan 2008
Location: France
Model: 8310
PIN: N/A
Carrier: Vodafone
Posts: 217
Default

erratum.

My code is wrong ont the comp.

The correct line is :

comp = comp * 2;
Offline  
Closed Thread



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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


SIMATIC, Memory Card, 4 Mbytes, 24 Mbytes, 256 Mbytes picture

SIMATIC, Memory Card, 4 Mbytes, 24 Mbytes, 256 Mbytes

$238.05



1PCS Memory iButton IC DALLAS/MAXIM DS1994L-F5 DS1994L+F5 DS1994L-F5+ picture

1PCS Memory iButton IC DALLAS/MAXIM DS1994L-F5 DS1994L+F5 DS1994L-F5+

$183.20



New Factory Sealed AB 1756-L61 SER B ControlLogix 2MB Memory Controller 1756L61 picture

New Factory Sealed AB 1756-L61 SER B ControlLogix 2MB Memory Controller 1756L61

$304.69



AVNET ULTRAZED SOM ZYNQ ULTRASCALE+ XCZU3EG SYSTEM ON MODULE -  picture

AVNET ULTRAZED SOM ZYNQ ULTRASCALE+ XCZU3EG SYSTEM ON MODULE -

$98.67



New AB 2711-NM14 4MB Memory Card Free fast shipping picture

New AB 2711-NM14 4MB Memory Card Free fast shipping

$372.76



NEW Original Allen Bradley 2080-MEMBAK-RTC Memory Module With RTC Plug-In picture

NEW Original Allen Bradley 2080-MEMBAK-RTC Memory Module With RTC Plug-In

$291.75







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