BlackBerryForums.com : Your Number One BlackBerry Community  
   

»Sponsored Links



Reply
 
LinkBack Thread Tools
  (#1 (permalink)) Old
goulamass Offline
Talking BlackBerry Encyclopedia
 
Posts: 204
Join Date: Jan 2008
Location: France
Model: 8310
PIN: N/A
Carrier: Vodafone
Default Resize a bitmap - 07-22-2008, 09:54 AM

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???
   
Reply With Quote
Sponsored Links
Please Login or Register to Remove these Advertisements!

  (#2 (permalink)) Old
sajika Offline
Knows Where the Search Button Is
 
Posts: 17
Join Date: May 2008
Model: 8310
PIN: N/A
Carrier: ATT
Default 07-22-2008, 02:25 PM

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
   
Reply With Quote
  (#3 (permalink)) Old
CELITE Offline
Thumbs Must Hurt
 
Posts: 129
Join Date: Dec 2005
Model: 8310
Carrier: Rogers
Default 07-22-2008, 02:56 PM

use scaleImage32 to set it to an arbitrary size
   
Reply With Quote
  (#4 (permalink)) Old
goulamass Offline
Talking BlackBerry Encyclopedia
 
Posts: 204
Join Date: Jan 2008
Location: France
Model: 8310
PIN: N/A
Carrier: Vodafone
Default 07-23-2008, 03:49 AM

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

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???
   
Reply With Quote
  (#6 (permalink)) Old
goulamass Offline
Talking BlackBerry Encyclopedia
 
Posts: 204
Join Date: Jan 2008
Location: France
Model: 8310
PIN: N/A
Carrier: Vodafone
Default 07-23-2008, 05:44 AM

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
   
Reply With Quote
  (#7 (permalink)) Old
goulamass Offline
Talking BlackBerry Encyclopedia
 
Posts: 204
Join Date: Jan 2008
Location: France
Model: 8310
PIN: N/A
Carrier: Vodafone
Default 07-23-2008, 09:11 AM

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
   
Reply With Quote
  (#8 (permalink)) Old
goulamass Offline
Talking BlackBerry Encyclopedia
 
Posts: 204
Join Date: Jan 2008
Location: France
Model: 8310
PIN: N/A
Carrier: Vodafone
Default 07-23-2008, 09:16 AM

After checking, my two variables never change.

What is wrong???
   
Reply With Quote
  (#9 (permalink)) Old
Ivanov Offline
Thumbs Must Hurt
 
Posts: 179
Join Date: Apr 2008
Location: Germany, BW
Model: -
PIN: N/A
Carrier: -
Default 07-23-2008, 09:18 AM

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

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.
   
Reply With Quote
  (#11 (permalink)) Old
goulamass Offline
Talking BlackBerry Encyclopedia
 
Posts: 204
Join Date: Jan 2008
Location: France
Model: 8310
PIN: N/A
Carrier: Vodafone
Default 07-23-2008, 09:34 AM

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);
   
Reply With Quote
  (#12 (permalink)) Old
goulamass Offline
Talking BlackBerry Encyclopedia
 
Posts: 204
Join Date: Jan 2008
Location: France
Model: 8310
PIN: N/A
Carrier: Vodafone
Default 07-24-2008, 03:25 AM

erratum.

My code is wrong ont the comp.

The correct line is :

comp = comp * 2;
   
Reply With Quote
Reply


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-2008 BlackBerryNews.com, BlackBerryFAQ.com, BlackBerryForums.com.
The names RIM © and BlackBerry © are registered Trademarks of Research In Motion Limited.
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.0.1