Reading an image

Blitz3D Forums/Blitz3D Programming/Reading an image

wmaass(Posted 2007) [#1]
What I want to do is read a bitmap and where I find the green value equal to 255 do something such as place an object on terrain. I have a bitmap with 1 pixel colored 0,255,0. When I run the code below to count how many green pixels I find I keep getting 4. I'm expecting 1. Any ideas?


Graphics3D 320,240,32,2
SetBuffer BackBuffer()

cam=CreateCamera()
CameraClsColor cam,0,0,255
light=CreateLight()
PositionEntity light,0,20,-25

grassmap=LoadImage("grassmap.bmp")
SetBuffer ImageBuffer(grassmap)

For d=0 To 255
For f=0 To 255
GetColor d,f
If ColorGreen() = 255
yg=yg+1
EndIf

Next
Next

SetBuffer BackBuffer()

While Not KeyDown( 1 )

RenderWorld
Text 0,0,yg
Flip
Wend

End


Stevie G(Posted 2007) [#2]
This work any better?

For d=0 To 255
	For f=0 To 255
		rgb = ReadPixel( d, f, ImageBuffer( grassmap ) )
		If ( ( rgb And $FF00 ) Shr 8 ) = 255
			yg = yg + 1
		EndIf
	Next
Next		



wmaass(Posted 2007) [#3]
That's perfect, thanks a bunch.


wmaass(Posted 2007) [#4]
I also found that my "1 pixel" brush wasn't 1 pixel. But your routine was better than mine anyway.