Android Question LoadBitmapSample & gravity center

LucaMs

Expert
Licensed User
Longtime User
I have an ImageView 100dip x 100dip. To set its bitmap I use this simple code:
B4X:
bmp = LoadBitmapSample(Dir, FileName, SampleWidth, SampleHeight)


ImageView1.Gravity = Gravity.CENTER
ImageView1.Bitmap = bmp
The first line is in a sub routine, to which I pass the size of the ImageView, then SampleWidth and SampleHeight will be 100dip.

Well, some images (jpg) larger than 100x100 are displayed completely (resized), other images appear the central part only.

(if I set gravity to FILL, the smaller image (256 x 256) appears fine, the largest is distorted, as it is rectangular, 3543 x 2215).

[Another strange thing is that Windows shows a preview of some pictures but not of others, although they are all jpg - pictures of the device connected to my PC]


The question is... guess... why?



P.S. Perhaps the question is badly expressed; in summary:

ImageView 100dip x 100dip - Gravity: Center
Picture1 3543 x 2215 - OK (small, resized but ok)
Picture2 256 x 256 - only the central part is displayed.
 
Last edited:

LucaMs

Expert
Licensed User
Longtime User
It is better to upload a small example that demonstrates it.
Done.
https://www.dropbox.com/s/r92fkcpfquhoocn/LoadBitmapSample.zip?dl=0

LoadBitmapSample can (and in most cases will) return an image larger than the values you specified.
Then it is unuseful, right?


You should use CreateBitmapSample if you want to set the exact size.
I found CreateScaledBitmap, probably you mean this. I tried it too in the test project.


Thank you, Erel.
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
It is not useful if you don't understand what is supposes to do.
In fact, I cannot understand and I should not suppose what it does; I should know what a method does studying a language manual. I have not found LoadBitmapSample in the two PDF guides provided.


P.S. I found only (on site):
upload_2016-1-6_13-12-35.png



My poor english and my lack of ability to understand suggest to me a proportional downsizing, if needed.


Also:
LoadBitmapSample can (and in most cases will) return an image larger than the values you specified
but the example parameters names are: MaxWidth and MaxHeight.
 
Last edited:
Upvote 0
Top