Android Question What LoadBitmapSample does exactly?

Erel

B4X founder
Staff member
Licensed User
Longtime User
Exactly as described:

SS-2016-01-06_17.24.28.png


The purpose of LoadBitmapSample is to reduce memory usage. It can be considered a bug to load an image with LoadBitmap instead of LoadBitmapSample (unless you know for sure that the image is not huge).

The variables names are less important.
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
"The decoder will subsample the bitmap if MaxWidth or MaxHeight are smaller that the bitmap dimensions."

subsample... I suppose it should return a proportional sample, smaller or equal to MaxWidth and MaxHeight. Is this correct?

In a project I get (w.h logs):

original (file): 3543.2215
ImageView : 293.293 (MaxWidth and MaxHeight I passed to LoadBitmapSample)
'sampled' : 443.277

442 is bigger than 293
277 is smaller than 293
 
Upvote 0

JordiCP

Expert
Licensed User
Longtime User
I think that it searches for the "nearest" power-of-2 (1/2, 1/4th, 1/8th...) subsample of the original bitmap which "better fits" the given maxWidth and maxHeight.

3543/293 = 2215/277 = 8 aprox (this is the subsampling)

Also, the scale factor of the subsampled bitmap remains (3543/2215 = 442/277 = 1.6 aprox )

As in your case you gave square dimensions for a non-square original bitmap, it made its best o_O
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
just had a quick look at it and the results are indeed strange.

I don't know if it is an implementation of @Erel or calls to standard api's.
 
Upvote 0
Top