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


Bunn 27850.0200 SH Server, 1.5G/5.7L, INF Series - New Open Box - Bunn SH Server picture

Bunn 27850.0200 SH Server, 1.5G/5.7L, INF Series - New Open Box - Bunn SH Server

$399.99



GIGABYTE MD72-HB2 REV 1.0 SP3 DDR4 128GB Server Motherboard Intel C621A LGA4189 picture

GIGABYTE MD72-HB2 REV 1.0 SP3 DDR4 128GB Server Motherboard Intel C621A LGA4189

$800.00



Windows Server 2025 RDS CAL 50 User Key License | |Multilingual picture

Windows Server 2025 RDS CAL 50 User Key License | |Multilingual

$91.24



IXON IXrouter3 IX2410 WiFi Industrial VPN Gateway Router + Antenna NEW picture

IXON IXrouter3 IX2410 WiFi Industrial VPN Gateway Router + Antenna NEW

$249.99



Intel S2600CP2 Server Board DBS2600CP2 with cables, FW CD docs overnight shippin picture

Intel S2600CP2 Server Board DBS2600CP2 with cables, FW CD docs overnight shippin

$195.00



MOXA NPORT IA-5150 Industrial Device Server picture

MOXA NPORT IA-5150 Industrial Device Server

$199.00







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