Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Posts: 16
Registered: ‎07-30-2012
My Device: None
My Carrier: Proximus

Scaling/ReScaling image & bitmap



I'm using an image of 1900x1700 px and I'm scaling & converting it to a bitmap.

Then I'm drawing a pointer on the scaled bitmap and after that I convert the drawn bitmap to an image.

After that I'm trying it to resize it to 1900x1700 but it does not happen I believe. My biggest issue is that I'm working with a zoomscreen and bitmaps do not support 1900x1700 resolutions.


Does anyone have an idea how to make this work?



package mypackage;

import net.rim.device.api.math.Fixed32;
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.system.EncodedImage;
import net.rim.device.api.system.PNGEncodedImage;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.extension.container.ZoomScreen;

public class BitmapFieldDemo extends UiApplication 
    public static void main(String[] args)
        BitmapFieldDemo theApp = new BitmapFieldDemo(); 

    public BitmapFieldDemo() 
    	BitmapFieldDemoScreen fdm = new BitmapFieldDemoScreen();

class BitmapFieldDemoScreen extends MainScreen
	EncodedImage map1 = EncodedImage.getEncodedImageResource("map.png");
    Bitmap tempBmp;
    Bitmap bitmapImage2 = Bitmap.getBitmapResource("pointer.png");
    EncodedImage image2;

    public BitmapFieldDemoScreen ()

    public ZoomScreen setScreen(){
    	tempBmp = getScaledBitmapImage(map1);

	Graphics g = Graphics.create(tempBmp); // draw on it, original map BMP is modified; x,y values are hardcoded
    g.drawBitmap(100, 100, bitmapImage2.getWidth(), bitmapImage2.getHeight(), bitmapImage2, 0, 0); // encode to PNG
    image2 = PNGEncodedImage.encode(tempBmp); // call the ZoomScreen
    ZoomScreen screen = new ZoomScreen(image2);// push the ZoomScreen
    return screen;

    private Bitmap getScaledBitmapImage(EncodedImage image)
        int currentWidthFixed32 = Fixed32.toFP(image.getWidth());
        int currentHeightFixed32 = Fixed32.toFP(image.getHeight());
        int width = image.getWidth() /7;
        int height = image.getHeight() /7;
        int requiredWidthFixed32 = Fixed32.toFP(width);
        int requiredHeightFixed32 = Fixed32.toFP(height);
        int scaleXFixed32 = Fixed32.div(currentWidthFixed32, requiredWidthFixed32);
        int scaleYFixed32 = Fixed32.div(currentHeightFixed32, requiredHeightFixed32);
        image = image.scaleImage32(scaleXFixed32, scaleYFixed32);
        return image.getBitmap();
    public static EncodedImage resizeImage(EncodedImage image, int newWidth, int newHeight) {
        int scaleFactorX = Fixed32.div(Fixed32.toFP(image.getWidth()), Fixed32.toFP(newWidth));
        int scaleFactorY = Fixed32.div(Fixed32.toFP(image.getHeight()), Fixed32.toFP(newHeight));
        return image.scaleImage32(scaleFactorX, scaleFactorY);



Posts: 1,634
Registered: ‎07-14-2008
My Device: Z10
My Carrier: Fido

Re: Scaling/ReScaling image & bitmap

For OS5+ you should be using ScaleInfo()


public void scaleInto(Bitmap dst,
                      int filterType,
                      int iAspectRatioOption)
Posts: 16
Registered: ‎07-30-2012
My Device: None
My Carrier: Proximus

Re: Scaling/ReScaling image & bitmap

the bitmap gets scaled. But the image does not.