I wanted to know if we can resize an image. Suppose if we want to draw an image of 200x200 actual size with a size of 100 x 100 size on our blackberry screen.
Thanks
I wanted to know if we can resize an image. Suppose if we want to draw an image of 200x200 actual size with a size of 100 x 100 size on our blackberry screen.
Thanks
I am posting this answers for newbie in Blackberry Application development. Below code is for processing Bitmap images from URL and Resizing them without loass of Aspect Ratio :
The Method resizeImage is called inside the method imageFromServer(String url). 1) the image from server is processed using EncodedImage img. 2) Bitmap bitmp = resizeImage(img.getBitmap(), 100, 100); parameters are passed to resizeImage() and the return value from resizeImage() is set to Bitmap bitmp.
For BlackBerry JDE 5.0 or later, you can use the scaleInto API.
Keep in mind that the default image scaling done by BlackBerry is quite primitive and generally doesn't look very good. If you are building for 5.0 there is a new API to do much better image scaling using filters such as bilinear or Lanczos.
I'm not a Blackberry programmer, but I believe some of these links will help you out:
Image Resizing Article
Resizing a Bitmap on the Blackberry
Blackberry Image Scaling Question
You can do this pretty simply using the
EncodedImage.scaleImage32()
method. You'll need to provide it with the factors by which you want to scale the width and height (as aFixed32
).Here's some sample code which determines the scale factor for the width and height by dividing the original image size by the desired size, using RIM's
Fixed32
class.If you're lucky enough to be developer for OS 5.0, Marc posted a link to the new APIs that are a lot clearer and more versatile than the one I described above. For example:
(Naturally you can substitute the filter/scaling options based on your needs.)