I assume you're saying that your BitmapField
is showing the image you retrieve cropped?
And you would like it to scale, perhaps scaled to fit the size of your BitmapField
? There's many ways to do that, but one is to resize the image after downloading, before giving it to the BitmapField
:
From this answer on resizing a Bitmap
public static Bitmap resizeImage(Bitmap originalImage, int newWidth, int newHeight) {
Bitmap newImage = new Bitmap(newWidth, newHeight);
originalImage.scaleInto(newImage, Bitmap.FILTER_BILINEAR, Bitmap.SCALE_TO_FILL);
return newImage;
}
(Note that the link I provided has an alternate method for resizing images, if you have to support BlackBerry OS < 5.0).
Then, use
Bitmap img = resizeImage(connectServerForImage(ImageUrl), 80, 70);
BitmapField bmp = new BitmapField(img) {
protected void layout(int width, int height)
{
setExtent(80, 70);
}
};
However, I believe that if you actually set the size of the Bitmap
img
to 80x70, then there's no need to also set the extent of the BitmapField
to 80x70. It should default to the size of the image you give it. So, you could simplify the code to:
BitmapField bmp = new BitmapField(img);