BlackBerry Forums Support Community
              

Closed Thread
 
Thread Tools
Old 02-03-2006, 05:18 PM   #1
ecarmody
Thumbs Must Hurt
 
Join Date: Apr 2005
Location: Portland, OR., USA
Model: 9800
Carrier: AT&T
Posts: 82
Default Resizing an image

Please Login to Remove!

Hi all,

From what I can figure out, I can resize a bitmap by setting the scale factor on a call to Bitmap.createBitmapFromBytes().
The issue I have with this is that the scale factor is a whole integer value. If an image is a little too big for the screen, the next scale value (2) makes it too small leaving white space around the border. I don't need to skew it, but at least the widest side should fit evenly to the screen.

Is there another approach to resizing an image to get a better fit? I'm looking for a java progamtic approach, not resizing an image using an editor.

Thanks for any comments.
Cheers,
Eric
Offline  
Old 05-06-2007, 11:09 PM   #2
mdwheaton
Thumbs Must Hurt
 
Join Date: Feb 2007
Model: 8100
Carrier: T-Mobile
Posts: 54
Default

Here's what I do to scale an image. There may be an easier way to do it by percentage of original image size, but I haven't found it.
Hope this helps.

EncodedImage bitmap = null;
String path = "/classpath/to/image.png";
InputStream in = ThisClass.class.getResourceAsStream(path);
byte[] data = new byte[in.available()];
in.read(data);
bitmap = EncodedImage.createEncodedImage(data, 0, data.length);

int divisor = Fixed32.toFP(100);

/**
* Change this number, < 100 makes the image bigger by
* percentage. i.e. 90 makes the image 110% normal size.
* By increasing, you will reduce the image size,
* e.g. 110 makes the image 90% normal size.
*/
int multiplier = Fixed32.toFP(110);

int fixedX = Fixed32.toFP(1);
/** First, divide the image scale by 100. */
fixedX = Fixed32.div(fixedX,divisor);
/** Now, multiply the image scale by the multiplier. */
fixedX = Fixed32.mul(fixedX,multiplier);

int fixedY = Fixed32.toFP(1);
fixedY = Fixed32.div(fixedY,divisor);
fixedY = Fixed32.mul(fixedY,multiplier);

bitmap = bitmap.scaleImage32(fixedX,fixedY);
in.close();

BitmapField bmp = new BitmapField();
bmp.setImage(bitmap);
Offline  
Old 05-07-2007, 10:50 AM   #3
ecarmody
Thumbs Must Hurt
 
Join Date: Apr 2005
Location: Portland, OR., USA
Model: 9800
Carrier: AT&T
Posts: 82
Default

Hi md,

Thanks for the reply. I note you used the scaleImage32. Back when I was originally working on my project I wasn't yet using the 4.2 JDE release. This is a nice ability to be able to use the scale function for 4.2 OS level, however I was building at the 4.0 level.

I was/am building my project at a 4.0 level and specifically did not want to jump up to 4.2 and eliminate a market segment that hasn't yet upgraded. I wonder if its even worth the effort anymore at this point, trying to maintain some backward compatibilty by supporting 4.0 level. On the otherhand, it may be presumptious to think everyone is running latest greatest 4.2 version. I still see 7290 devices, even within our company.

Cheers,
Eric
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


Momentary Toggle Switch SPDT ON Off ON 3 Pin with Waterproof Boots 3 PCS picture

Momentary Toggle Switch SPDT ON Off ON 3 Pin with Waterproof Boots 3 PCS

$7.46



PDGXAC - Eaton Power Defense Switch, Pigtail Connector picture

PDGXAC - Eaton Power Defense Switch, Pigtail Connector

$169.99



HBLDS6 Hubbell disconnect switch picture

HBLDS6 Hubbell disconnect switch

$430.00



200 Amp Transfer Switch, 48000W General-Duty Double-Throw Safety Switch picture

200 Amp Transfer Switch, 48000W General-Duty Double-Throw Safety Switch

$99.74



EcoFlow 6-Circuit Manual Transfer Switch for Portable Generators 30A  306A1-ECO picture

EcoFlow 6-Circuit Manual Transfer Switch for Portable Generators 30A 306A1-ECO

$169.95



Original EZ GENERATOR TRANSFER SWITCH - UL / CSA Approved - Made in USA picture

Original EZ GENERATOR TRANSFER SWITCH - UL / CSA Approved - Made in USA

$89.99







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