View Single Post
Old 05-10-2010, 08:53 AM   #4 (permalink)
New Member
aman_vivek's Avatar
Join Date: May 2010
Location: India
Model: 9350
OS: 4.7os
Carrier: airtel
Posts: 3
Post Thanks: 0
Thanked 0 Times in 0 Posts

Following code is used to resize bitmap(if bitmap format is jpg only replace png to jpg from following code,below code work well both for png and jpg file).

import net.rim.device.api.math.Fixed32;
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.system.PNGEncodedImage;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.BitmapField;
import net.rim.device.api.ui.container.MainScreen;

class UserInterfaceDemo extends UiApplication


//pushScreen(new CustomScreen());
pushScreen(new BitmapDemo());

public static void main(String args[])
UserInterface app=new UserInterface();


class BitmapDemo extends MainScreen

public BitmapDemo()
Bitmap b=Bitmap.getBitmapResource("bg.png");//image of size 320x240
PNGEncodedImage image =PNGEncodedImage.encode(b);
Bitmap b1=toSize(image,95, 80).getBitmap();//image of size 95x80
add(new BitmapField(b1));


public static PNGEncodedImage toSize(PNGEncodedImage encoded, int newWidth, int newHeight)
int curWidth = encoded.getWidth();
int curHeight = encoded.getHeight();
int xnumerator = Fixed32.toFP(curWidth);
int xdenominator = Fixed32.toFP(newWidth);
int xscale = Fixed32.div(xnumerator, xdenominator);
int ynumerator = Fixed32.toFP(curHeight);
int ydenominator = Fixed32.toFP(newHeight);
int yscale = Fixed32.div(ynumerator, ydenominator);
return (PNGEncodedImage) encoded.scaleImage32(xscale, yscale);

Offline   Reply With Quote