Android Question Read x,y from getPixels

Fusseldieb

Active Member
Licensed User
Longtime User
Hi,
I use getPixels() to get pixels from the entire image and I realize that I can read one pixel at a time defining 0,0 or 0,1 and so on, but everytime I use that funcion, it slows the app down. Knowing that, I want to read the entire image at once, store it into an Integer and read later with x and y.

B4X:
Dim p() As Int

p=getPixels(Canvas1.Bitmap,0,X,Y,Canvas1.Bitmap.Width,Canvas1.Bitmap.Height)

Here I read the entire image, but how can i later read an x and y coordinate? Like this:

B4X:
p(12,49)
Obviously that doesn't work, but I can't figure out how to make that work.
 

stevel05

Expert
Licensed User
Longtime User
From a quick test it appears that the returned array holds rows of pixels in sequence. So if the bitmap is 10 x 10, the contents of the array indices 0-9 will be row 1, 10 - 19 will be row 2 etc.

So you can access each pixel as
B4X:
Pixels(X + Y * ImageWidth)
 
Upvote 0
Top