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
Developer
Posts: 144
Registered: ‎12-20-2008
My Device: Not Specified

Re: Zoom on Bitmap Field

 

How i can use your code to load the existing image from a bitmap

this is the actual bitmap

 

_mapField.setBitmap(Bitmap.createBitmapFromPNG(
                                                                                bv.getArray(), 0, -1));
                                                                _mapFieldZoom=_mapField();

how to load this image into your class

ScrollBitmapField.            (

 

New Developer
Posts: 18
Registered: ‎02-03-2009
My Device: Not Specified

Re: Zoom on Bitmap Field

[ Edited ]

@Raiden

 

ScrollBitmapField sbf = new ScrollBitmapField();

EncodedImage eImage = EncodedImage.getEncodedImageResource("xmas.png");

sbf.loadPicture(eImage)

add(sbf);

 

Works for me but using the code Nicolas provided I am having issues,

 

The loadPicture() returns true and it has the right dimensions but the error I am having is that that _height is always 1073741823

so graphics paint is being passed a huge value causing the image not to be displayed

 

Also setFitZoom() always returns 0, this is on the Storm 9530

 

1073741823 is Integer's max value / 2

 

It seems that using Display.getHeight() for setting _height works. so the changes I made was as follows:

public boolean loadPicture(EncodedImage picture) {

//EVERYTHING THE SAME EXCEPT ADD THIS LINE

pictureDisplayed = picture.getBitmap();

 

then

 protected void layout(int width, int height) {

_width = width;

_height = Display.getHeight();
setExtent(_width, _height);

}

 

 

Message Edited by Rogu on 06-04-2009 12:54 PM
Developer
Posts: 51
Registered: ‎09-18-2008
My Device: Not Specified

Re: Zoom on Bitmap Field

hi'

 

what is the mini version of jde to use for this and simultor its works for.

is it  works only for bold and strom device or else other lower version also.

 

please help me

 

thanks in advance.

 

Developer
Posts: 51
Registered: ‎09-18-2008
My Device: Not Specified

Re: Zoom on Bitmap Field

hello,

 

how to check the scaling or zoomin and zoomout  of an image in the simulator and device.

 

because i am new to the concept.

 

Thanks in advance.

Developer
Posts: 216
Registered: ‎02-18-2010
My Device: 9350,8520
My Carrier: no

Re: Zoom on Bitmap Field

Please try below code package cus; 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 { UserInterfaceDemo() { pushScreen(new BitmapDemo()); } public static void main(String args[]) { UserInterface app=new UserInterface(); app.enterEventDispatcher(); } } 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)); invalidate(); } 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); } }
Developer
Posts: 216
Registered: ‎02-18-2010
My Device: 9350,8520
My Carrier: no

Re: Zoom on Bitmap Field

 

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
{
	UserInterfaceDemo()
	{
		pushScreen(new BitmapDemo());
	}
	public static void main(String args[])
	{
		UserInterface app=new UserInterface();
		app.enterEventDispatcher();
	}
}

 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));
		invalidate();
		
	}
	

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);
}
	
}