How to draw png images with specific size and position on the screen?
+3
A:
Somewhere in an initialization function:
Image myImage = Image.createImage("/myimage.png");
And in the paint function of your canvas:
g.drawImage(myImage, posX, posY, Graphics.TOP|Graphics.LEFT);
(where g is the Graphics object you get from the paint function)
edit: fixed small error as pointed out in comments
Toad
2009-09-15 10:56:33
completely right! will change it
Toad
2009-09-15 13:37:13
+1
A:
If you use net.rim.device.api.system.PNGEncodedImage or one of the other classes extended from net.rim.device.api.system.EncodedImage you can use the scaleImage32(int scaleX, int scaleY) method (available in OS 4.2 and latter) to scale the image to the size you want. Be aware though that scaleX and scaleY, though typed as int are actually net.rim.device.api.math.Fixed32 so to display the image at one half size:
EncodedImage halfSize = myImage.scaleImage32(Fixed32.toFP(2), Fixed32.toFP(2));
Or for an image twice original size:
EncodedImage twiceSize = myImage.scaleImage32(Fixed32.tenThouToFP(5000), Fixed32.tenThouToFP(5000));
Richard
2009-09-15 12:03:24