BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 07-10-2007, 04:27 AM   #1 (permalink)
Thumbs Must Hurt
 
Join Date: Jun 2007
Model: 8800
PIN: N/A
Carrier: GPRS
Posts: 68
Post Thanks: 0
Thanked 0 Times in 0 Posts
Smile A problem of draw image

Please Login to Remove!

Hi,everyone:
I'm learning development on JDE 4.1.0, and I have a problem in drawing a image! The image is from Internet through a url and it's about 800*600 in the JPG format.
first:
image = EncodedImage.createEncodedImage(imageData, 0, imageData.length );
I create the image according the imageData received from Net in bytes;

then:
graphics.drawImage( x, y, width, height, this.image, 0, v_CurrentZoomX, v_CurrentZoomY);
I use this sentence to draw the image!

But there is a problem, the image is too big and can not be put in the screen. I can see that there is only one part of image in the screen .I search for
drawImage method in RIM and it says the function will cut dowm the overplus part.
I do not find some other function to zoom out the image , so can anybody give me some ideas to do it?
or I should write the a new class to realize the ability of zonnm out?
Thank you very much !
Offline  
Old 07-10-2007, 05:39 AM   #2 (permalink)
CrackBerry Addict
 
Join Date: Jun 2005
Location: Manchester, UK
Model: BOLD
Carrier: t-mobile
Posts: 714
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

mdwheaton over on the official bberry dev forum posted this code that works well, i've used it before:

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);
__________________
new job doesn't allow a public profile - please do not contact this user with questions, you will not get a response. good luck!
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.