When a bitmap is loaded from a file, are its property width and height dip values?
A sample from B4A writes codes in the following way:
w = bitmap1.width * 100dip / 100
From this line of code, I guess that the width of a bitmap is not dip value.
And if an imageview load a bitmap from file, can it auto adjust the size of the bitmap?
If not, would the image become very small on HD screen?
do we need to convert the size of bitnap to dip, if we draw with its size?
Dim Bitmap1 As Bitmap Bitmap1.Initialize(File.DirAssets, "X.jpg") Dim DestRect As Rect DestRect.Initialize(0, 0, Bitmap1.Width, Bitmap1.Height) Canvas1.DrawBitmap(Bitmap1, Null, DestRect)
And when an imageview load a bitmap, can it automatically convert the size of the bitmap to dip before drawing it. In this case, we are unable to manually convert the size of the bitmap to dip, if the gravity is center.
The width and height are measured in pixels. If you want to scale the image automatically then you need to explicitly set the ImageView width and height and set the Gravity to Fill.
It depends on what you are trying to achieve. If you want to stretch the image to always have the same (approximate) physical size then you should use:
No. dip returns an integer value. So if the scale is 1.5 for example, 1dip will return 1. 100dip / 100 will return the correct value.
Another option is to use DipToCurrent keyword: