GrabCanvas?

Monkey Forums/Monkey Programming/GrabCanvas?

Chroma(Posted 2013) [#1]
Any way to draw to the screen and then grab and creat an image of it quickly?


dave.h(Posted 2013) [#2]
i would love this function but as far as i know it cant be done.I really hope im wrong and someone knows better.


Midimaster(Posted 2013) [#3]
didn't mark add exactly this? ReadPixels()?


Capn Lee(Posted 2013) [#4]
Method grabforfade:Int()
	scrshot = CreateImage(SCREEN_WIDTH, SCREEN_HEIGHT)
	Local pixels:Int[] = New Int[SCREEN_WIDTH * SCREEN_HEIGHT]
	ReadPixels(pixels, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)
	scrshot.WritePixels(pixels, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)
	Return 0
End


Obviously scrshot is whatever image you want
this needs to be called from onrender()

there is an example bit of code that utilises this method here in this thread


dave.h(Posted 2013) [#5]
awesome this works great just tested it. soooo glad i was wrong.Thanks


Chroma(Posted 2013) [#6]
Great thanks. im gonna use this to avoid drawing background sprites. im going to draw them once...grab an image of them and just display that instead!


Chroma(Posted 2013) [#7]
What about transparency?


therevills(Posted 2013) [#8]
Check out the pixel perfect test code: http://www.monkeycoder.co.nz/Community/posts.php?topic=3488#36692

You need to specify a mask colour (black in this example).

' convert the mask colour (black) to alpha
		For Local i:Int=0 Until image.Width() * image.Height()
			Local argb:Int = pixels[i]
			Local a:Int = (argb Shr 24) & $ff
			Local r:Int = (argb Shr 16) & $ff
			Local g:Int = (argb Shr 8) & $ff
			Local b:Int = argb & $ff

			If a = 255 And r = 0 And g = 0 And b = 0 Then
				a = 0
				argb = (a Shl 24) | (r Shl 16) | (g Shl 8) | b
				pixels[i] = argb
			End
		Next
		
		image.WritePixels(pixels, 0, 0, image.Width(), image.Height())



Chroma(Posted 2013) [#9]
What I need is a function that can be fed an image and a list of 2d vectors (x,y) and return a single image of the images at all the vectors and any open squares will be transparent. That's what I NEED! XD

Function FuseImage:Image(image_file:String, vec_list:List<Vec2>)
     Local image:Image = LoadImage(image_file)
     For local v:Vec2 = Eachin vec_list
          DrawImage image, v.x, v.y
     Next
     Local this:Image = CreateImage(width, height)
     Local pixels:Int[] = New Int[width * height]
     ReadPixels(pixels,0,0,width,height)
     this.WritePixels(pixels,0,0,width,height)
     Return this
End Function


The above is pseudo code but OMG that would rawk!