canvas

BlitzMax Forums/BlitzMax Programming/canvas

Cronos(Posted 2007) [#1]
how read pixel from canvas , speed code ???

Function GetPixel(x:Int, y:Int, r:Int Var, g:Int Var, b:Int Var)
Local TempPixmap:TPixmap = GrabPixmap(x,y,1,1)
Local TempPtr:Byte Ptr = TempPixmap.PixelPtr(0,0)
r = TempPtr[2]
g = TempPtr[1]
b = TempPtr[0]
End Function


N(Posted 2007) [#2]
Sorry, what?


Cronos(Posted 2007) [#3]
how read pixel fast from canvas ??


N(Posted 2007) [#4]
Last I checked, there was no way to read pixel data quickly from a canvas or graphics buffer.


ImaginaryHuman(Posted 2007) [#5]
For OpenGL at least I'd recommend you simply define an Integer and then pass the pointer to that integer as a parameter to glReadPixels() and read just 1 pixel, it will put the value into the integer. You have to set up the glreadpixels properly with a few other commands first. This should be faster than creating a new pixmap each time, converting the coordinates into an offset, reading into the memory (which uses glreadpixels internally for gl), and then extracting the components. You could also use a byte pointer pointing to the integer to extract.