Problem with LoadBitmapSample

gadgetmonster

Active Member
Licensed User
Longtime User
Hi All

My Activity has an image view whose width is 100%x (720 in my case) and has a height set to 384. What I am trying to do is take a photo that the user has selected and set the width of that photo to the width of the image view and then centre the resized photo in the image view.

I successfully get the width and height of the photo (1632 x 1224) and run it through the following code to get the new photo size based on the width of my image view (Yes width is held in array pos 1 and height in 0).

B4X:
      Dim scale As Float = Activity.Width / bitmapSize(1)
      newWidth = bitmapSize(1) * scale
      newHeight = bitmapSize(0) * scale


This works and gives me a new size of 720 x 540. So far so good.

So now I use the following to create a new bitmap at that size:

B4X:
Dim scaledImage As Bitmap = LoadBitmapSample(entry.PhotoDir, entry.PhotoFilename, newWidth, newHeight)

If the image is landscape this results in an image which is bigger than I specified but that is ok but if its portrait the scaledimage is the same size as the original which is not so good.

When I then do this:

B4X:
imgPhoto.Bitmap = scaledImage

The image is not the reduced image but looks like the original sized image (landscape and portrait).

What am I doing wrong?
 
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0
Top