GrabImage and pixel work

BlitzMax Forums/BlitzMax Programming/GrabImage and pixel work

Curtastic(Posted 2006) [#1]
Hi I am trying to conert graphical code from blitzbasic to blitzmax, and I'm having a slight problem with drawing to (what was) imagebuffers.

In this code, every loop it simply brightens the blue value of each pixel in the image that isn't black.

Clicking the left mouse button should do nothing, but it is causing the image to "grow". New pixels are showing up when it is grabimaged.

I'm just wondering if there is any way to draw to an image, via grabimage, without getting new nonblack pixels around the edges.

Strict

Graphics 800,600

Local image:timage
Local x,y
Local pixmap:TPixmap
Local blue

'make the image
image=CreateImage(66,66)
SetColor 0,0,50
DrawRect 20,20,10,10
GrabImage image,0,0

Repeat
	'brighten all nonblack pixels
	pixmap=LockImage(image)
	For y=0 Until image.height
		For x=0 Until image.width
			blue=ReadPixel(pixmap,x,y) & $FF
			If blue>0 And blue<200 Then
				WritePixel pixmap,x,y,$FF000000+blue+1
			EndIf
		Next
	Next
	UnlockImage image
	
	'draw
	SetColor 255,255,255
	DrawImage image,0,0
	Flip
	Cls
	
	If KeyHit(key_escape) Then End
	
	'should do nothing...
	If MouseHit(1) Then
		Cls
		DrawImage image,0,0
		'this is where I would draw to the image.
		GrabImage image,0,0
	EndIf
	
Forever



Dreamora(Posted 2006) [#2]
image.height / image.width are the wrong values to use.

Use ImageHeight(image)-1 and ImageWidth(image)-1

Reason is that image.height / .width hold the real width / height values, not the original size values (because non-power of 2 will be extended to power of two internally)


Curtastic(Posted 2006) [#3]
Ya but I'm using For/Until, which stops one before it reaches the max value


tonyg(Posted 2006) [#4]
I must be missing something as that code seems to work for me. Imagewidth(image)/imageheight(image) stays at 66,66
<edit> Second thoughts... it needs a few mouse taps.


TomToad(Posted 2006) [#5]
This looks like a bug to me. It isn't making the image any bigger, it's just changing the value of pixels in the backbuffer when grabbing. If you use SetGraphicsDriver GLMax2DDriver(), you still get problems, but the pattern is different.


tonyg(Posted 2006) [#6]
Yep, I agree. I am pretty sure this was reported before.