Welcome!

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

Reply
Highlighted
Developer
Posts: 224
Registered: ‎03-29-2012
My Device: 9900
My Carrier: Wind
Accepted Solution

Scaling Bitmap background, 9900 vs 9700

App looks all right on the 9900 but of course the 9700 has a different screen and my bitmaps were created to fit the 9900. I have checked other threads but all they advise to do is use the .scaleInto() method, which is not working for me as shown: 

Bitmap bgfirstscreen = Bitmap.getBitmapResource("peerreview2.jpg");
			Bitmap bgfirstscreenScaled = new Bitmap(Display.getWidth(),Display.getHeight());
			bgfirstscreen.scaleInto(bgfirstscreenScaled, Bitmap.FILTER_LANCZOS);
			Background background = BackgroundFactory
					.createBitmapBackground(bgfirstscreen);

 Is this all that typically has to be done to scale the bitmap? It is being used as the background image for my app's screen.

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

Re: Scaling Bitmap background, 9900 vs 9700

use this func instead and pass a aspect ratio to SCALE_TO_FILL or SCALE_TO_FIT

 

void

scaleInto(Bitmap dst, int filterType, int iAspectRatioOption)

Developer
Posts: 224
Registered: ‎03-29-2012
My Device: 9900
My Carrier: Wind

Re: Scaling Bitmap background, 9900 vs 9700

so its the same thing but include an aspect ratio option at the end?

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

Re: Scaling Bitmap background, 9900 vs 9700

yes. retaining aspect ratio will make the resize look realistic and not stretched. 

 

read the bitmap java doc on the function.  try FIT first and then FILL if you don't like the top and bottom white borders.

Developer
Posts: 224
Registered: ‎03-29-2012
My Device: 9900
My Carrier: Wind

Re: Scaling Bitmap background, 9900 vs 9700

[ Edited ]

Hmm odd, I had tried that earlier to no avail, I used fit, I haven't tried the other, however, by what you said it should be working. The image appears far too largermeven though it was created slightly bigger for the 9900, any thoughts on why the 9700 essentially magnifying it and perhaps why the scaleInto method as described  in the code snippet is failing?

Developer
Posts: 209
Registered: ‎04-30-2011
My Device: BlackBerry Z10
My Carrier: Airtel

Re: Scaling Bitmap background, 9900 vs 9700

Hi vingilot

 

Try this.

 

    public static Bitmap getScaledBitmapImage(String imagename,int wd,int ht) 
    {
        EncodedImage image = EncodedImage.getEncodedImageResource(imagename);
        if(image.getWidth()==wd && image.getHeight()==ht)
                return image.getBitmap();
        int currentWidthFixed32 = Fixed32.toFP(image.getWidth());
        int currentHeightFixed32 = Fixed32.toFP(image.getHeight());
        int width = wd;
        if(width == -1)
            width=image.getWidth();
        int height = ht;
        if(height == -1)
            height=image.getHeight();
        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();
    }

 

Thanks

Pawan

Developer
Posts: 224
Registered: ‎03-29-2012
My Device: 9900
My Carrier: Wind

Re: Scaling Bitmap background, 9900 vs 9700

you sir, are my new best friend.