Where's my pixel?

boten

Active Member
Licensed User
Longtime User
A large image (say 600x600) is "scaled down" on a panel by factor (say 10) resulting in an image drawn as 60x60
B4X:
Dim bdz As BitmapDrawable
Dim pnl as Panel
Dim cvs as Canvas
Dim rct as Rect

bdz.Initialize(LoadBitmap(File.DirAssets, "anyimage.gif"))
bdz.Gravity = Gravity.FILL

cvs.Initialize(pnl)
rct.Initialize(X0,Y0,X0+60,Y0+60)
cvs.DrawDrawable(bdz,rct)

This works fine, But now I want to get the color of a pixel at (X,Y) withing the drawn image.

doing:
B4X:
Dim bmp As Bitmap
bmp=bdz.Bitmap
p=bmp.GetPixel(X-X0,Y-Y0)

does not work and I need to code it as:
B4X:
Dim bmp As Bitmap
bmp=bdz.Bitmap
p=bmp.GetPixel(10*(X-X0),10*(Y-Y0))
Basically "translating" the coordinates within the drawn picture to the "bigger" coordinates of the original picture.

Is there a way to get the value of a pixel on the screen, REGARDLESS of how or from where it was painted?
 
Top