get pixel color

BlitzMax Forums/BlitzMax Programming/get pixel color

How can I get the pixel color of a specific pixel of a TImage?
Is there any way to do it?

Graphics 800, 600

Local image:TImage = LoadImage("boxtexture.bmp")

Local pimage:TPixmap = LockImage(image)

While y < image.Height
    x = 0
    While x < image.width
      col = ReadPixel( pimage, x, y )
      a = ( col & $ff000000)
      r = ( col & $ff0000 ) Shr 16
      g = ( col & $ff00 ) Shr 8
      b = ( col & $ff )
	  Print a + ": " + r + ": " + g + ": " + b
      x:+ 1
    Wend
    y:+ 1
Wend

UnlockImage(image)


Edit: FIIIIIIIIIXXXXXXXXXXXXXXEEEEEEEEEEEEEEED!!!!!!!!! ^^

EDIT: FIXXXEEED again now uses read pixel

This way is OpenGL only

http://www.blitzbasic.com/Community/posts.php?topic=56071#623849

the second way is to convert a Timage into a Pixmap and then use the ReadPixel method

Thanks!! It worked :D

Hi
There are more ways to get the pixel color from pixmaps. Diablos is the slowest. Look at this small test.

Graphics 800, 600,0

Const TestLoops:Int = 50

Local TestImage:TImage = CreateImage(256, 256)
Local Time:Int
Local i:Int

For Local x:Int = 0 Until 256
	For Local y:Int = 0 Until 256
		SetColor Rand(0,255), Rand(0,255), Rand(0,255)
		Plot x, y
	Next 
Next 


GrabImage(TestImage, 0, 0)

Print ""


Time = MilliSecs()

For i = 0 Until TestLoops
	CheckImage1(TestImage)
Next 

Time = MilliSecs()-Time

Print "CheckImage1 time (millisecs): "+Time





Time = MilliSecs()

For i = 0 Until TestLoops
	CheckImage2(TestImage)
Next 

Time = MilliSecs()-Time

Print "CheckImage2 time (millisecs): "+Time





Time = MilliSecs()

For i = 0 Until TestLoops
	CheckImage3(TestImage)
Next 

Time = MilliSecs()-Time

Print "CheckImage3 time (millisecs): "+Time



End




Function CheckImage1(Image:TImage)
	Local pimage:TPixmap = LockImage(image)
	While y < image.Height
	    x = 0
	    While x < image.width
	      col = ReadPixel( pimage, x, y )
	      a = ( col & $ff000000)
	      r = ( col & $ff0000 ) Shr 16
	      g = ( col & $ff00 ) Shr 8
	      b = ( col & $ff )
	      x:+ 1
	    Wend
	    y:+ 1
	Wend
	UnlockImage(image)
End Function




Function CheckImage2(Image:TImage)
	Local pimage:TPixmap = LockImage(image)
	While y < pimage.Height
	    x = 0
	    While x < pimage.width
	      col = pimage.ReadPixel(x, y )
	      a = ( col & $ff000000)
	      r = ( col & $ff0000 ) Shr 16
	      g = ( col & $ff00 ) Shr 8
	      b = ( col & $ff )
	      x:+ 1
	    Wend
	    y:+ 1
	Wend
	UnlockImage(image)
End Function



Function CheckImage3(Image:TImage)
	Local pimage:TPixmap = LockImage(image)
	For Local x:Int = 0 Until pimage.Width
	    For Local y:Int = 0 Until pimage.Height
	      Local PixelData:Byte Ptr = pimage.PixelPtr(x,y)
	      r = PixelData[0]
	      g = PixelData[1]
	      b = PixelData[2]
		  a = PixelData[3]
		Next 
	Next 
	UnlockImage(image)
End Function



Mfg Suco