05-12-2009 01:42 PM
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.VerticalFieldManag
er#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
Solved! Go to Solution.
06-26-2009 03:58 PM
06-26-2009 04:30 PM - edited 06-26-2009 04:33 PM
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
11-04-2009 01:14 AM
Hi,
The code doesn't work for me.can you please tell me how have you used it?
11-04-2009 01:19 AM
Are you getting any exceptions?
11-04-2009 01:23 AM - edited 11-04-2009 01:31 AM
Sry,i m editing this message.The code works.I made mistake in my custom class.Thanks!!!!!!!!!
11-04-2009 02:09 AM
Thanks for updating.
11-10-2010 11:48 AM
anybody who has used ImageTransformControl in blackberry 5.0??
if yes plz mail ur code snippet