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: 113
Registered: ‎04-09-2009
My Device: Not Specified
Accepted Solution

How to resize Bitmap at runtime ?

Hi,

  I have created a Bitmap which reads directly from a file. The actual size of the image(test.png) is 360x50. I display this bitmap in a BitmapField.  Now I want to display this image in my application in such a way that, it should take the width of the screen and adjust (expand or compress) accordingly based on the TILT of the device( in case of BB Storm). My code is as below:

 

{ Bitmap image = Bitmap.getBitmapResource("mainmenu_green.png"); BitmapField bmpMainMenu = new BitmapField(image); MenuScreenVFM verticalManager = new MenuScreenVFM(); verticalManager.add(bmpMainMenu); add(verticalManager ); } //MenuScreenVFM Class.. static class MenuScreenVFM extends VerticalFieldManager { // Constructor private MenuScreenVFM() { super(Manager.VERTICAL_SCROLL | Manager.VERTICAL_SCROLLBAR | VerticalFieldManager.FIELD_HCENTER); } net.rim.device.api.ui.container.VerticalFieldManager#sublayout(int,int) */ protected void sublayout(int width, int height) { int nTop = 65; Field field = getField(0); layoutChild(field, Display.getWidth(), 40); setPositionChild(field, 0, nTop); setExtent( Display.getWidth(), Display.getHeight()); } }

 

 

   The image should stretch/compress based on the screen width. Any info/code would be really highly appreciated.

 

Thanks,

-DK

Developer
Developer
Posts: 137
Registered: ‎06-01-2009
My Device: Not Specified

Re: How to resize Bitmap at runtime ?

I am wondering if you were able to resolve your issue, because I have the same problem and I am not able to stretch/squeeze the image (bitmap).
Developer
Posts: 113
Registered: ‎04-09-2009
My Device: Not Specified

Re: How to resize Bitmap at runtime ?

[ Edited ]

 I created a CustomBitmapField extends from Field and for scaling the image I used the following code:

public static EncodedImage scaleImageToWidth(EncodedImage encoded, int newWidth) { return scaleToFactor(encoded, encoded.getWidth(), newWidth); } public static EncodedImage scaleImageToHeight(EncodedImage encoded, int newHeight) { return scaleToFactor(encoded, encoded.getHeight(), newHeight); } public static EncodedImage scaleToFactor(EncodedImage encoded, int curSize, int newSize) { int numerator = Fixed32.toFP(curSize); int denominator = Fixed32.toFP(newSize); int scale = Fixed32.div(numerator, denominator); return encoded.scaleImage32(scale, scale); } protected void paint(Graphics graphics) { graphics.setColor(backgroundColour); graphics.drawImage(0, 0, Display.getWidth(), fieldHeight, this.scaleImageToWidth(bmpBG, Display.getWidth()), 0, 0, 0); }

 

 

 

   Let me know if it works..if works please set Kudos.. which'll encourage whoever post the solution

 

Regards,

-DK

Message Edited by dkumar on 06-26-2009 04:33 PM
Developer
Posts: 528
Registered: ‎10-06-2009
My Device: 9800,BB Dev Alpha,z10 limited edition
My Carrier: Vodafone

Re: How to resize Bitmap at runtime ?

Hi,

The code doesn't work for me.can you please tell me how have you used it?

Rujuta Trivedi
Developer
Posts: 3,951
Registered: ‎07-15-2008
My Device: Not Specified

Re: How to resize Bitmap at runtime ?

Are you getting any exceptions?


Use Search. "Accept Solution" If the problem is resolved.
Developer
Posts: 528
Registered: ‎10-06-2009
My Device: 9800,BB Dev Alpha,z10 limited edition
My Carrier: Vodafone

Re: How to resize Bitmap at runtime ?

[ Edited ]

Sry,i m editing this message.The code works.I made mistake in my custom class.Thanks!!!!!!!!!

Rujuta Trivedi
Developer
Posts: 3,951
Registered: ‎07-15-2008
My Device: Not Specified

Re: How to resize Bitmap at runtime ?

Thanks for updating.


Use Search. "Accept Solution" If the problem is resolved.
Contributor
Posts: 12
Registered: ‎09-16-2010
My Device: 9000
My Carrier: t-mobile

Re: How to resize Bitmap at runtime ?

anybody who has used ImageTransformControl in blackberry 5.0??

if yes plz mail ur code snippet