How To create a Timage in realtime

BlitzMax Forums/BlitzMax Beginners Area/How To create a Timage in realtime

I mean, i dont want to load a pitmap and then make it a timage from it, i want to create an white oval for example, and make a timage from that oval so i can manipulate it in many ways.

What is faster? to drawoval each frame or to make a timage from the oval drawn?.

Thanks.

Look at the CreateImage() and GrabImage() commands. I'd expect blitting an image to be faster than drawing a geometric shape but there's only one way to find out for sure ;)

Let me see if i get it right:

Createimage makes an empty timage with its width and height.

Grabimage copyies a piece of the backbuffer using a timage width and height at a certain x and y coords and pastes it into a timage. Something like a cookie cutter?.

So, if i want a white masked circle i would need to draw it before any image is drawn on the backbuffer, and use the cls color matching the mask color, right?.

Thanks again.

is this something like what your after?

Strict
 Graphics 800, 600
 
 Global tempPic:TImage
 
 Global background:TImage = LoadImage("bg.png") 
 Global forground:TImage = LoadImage("fg.png") 
 Global mask:TImage = LoadImage("mask.png") 
  
 GetImage() 
 
 Repeat
 	Cls
	TileImage background, 0, 0
	DrawImage tempPic, MouseX(), MouseY() 
	Flip
 Until KeyDown(KEY_ESCAPE) 
 
 
 
 Function GetImage() 
 	SetMaskColor 255, 255, 255
 	Cls
	DrawImage forground, 0, 0
	DrawImage mask, 0, 0
	tempPic = CreateImage(256, 256) 
	GrabImage tempPic, 0, 0
 End Function


images used:

bg.png
http://www.mediafire.com/?jvdy4gwjdtm

fg.png
http://www.mediafire.com/?fjrlvjjrwcb

mask.png
http://www.mediafire.com/?mmzylhxkdb1

EDIT:
after rereading the thread instead of just skimming over it, it doesn't look like this is exactly what you need. but i hope still helps somewhat.

Let me see if i get it right:

Createimage makes an empty timage with its width and height.

Grabimage copyies a piece of the backbuffer using a timage width and height at a certain x and y coords and pastes it into a timage. Something like a cookie cutter?.

So, if i want a white masked circle i would need to draw it before any image is drawn on the backbuffer, and use the cls color matching the mask color, right?.

That's pretty much it, except the mask defaults to black so, using MASKBLEND to draw the image, you'll get a masked oval regardless of the background colour.

OOP-fied example:
SuperStrict
SeedRnd(MilliSecs())

Const GWIDTH:Int = 800
Const GHEIGHT:Int = 600
Const OVAL_SIZE:Int = 32
Const NUMBER_OF_PARALLAX_FIELDS:Byte = 4

Graphics GWIDTH,GHEIGHT
OvalField.Init(NUMBER_OF_PARALLAX_FIELDS)
SetClsColor 100,200,200

While Not KeyHit(KEY_ESCAPE)
	Cls
	OvalField.Update()
	Flip True
Wend

Type OvalField
	Global OvalPic:TImage = CreateImage(OVAL_SIZE,OVAL_SIZE)
	Global OvalList:TList = CreateList()

	Function Init(Fields_arg:Byte)
		SetBlend SOLIDBLEND
		Cls
		DrawOval 0,0,OVAL_SIZE,OVAL_SIZE
		GrabImage OvalPic,0,0
		
		For Local Scanline:Int = 0 To (GHEIGHT - 1)
			Local NewOval:Oval = New Oval
			NewOval.YPos = Scanline
			NewOval.XPos = Rand(0,GWIDTH-1)
			NewOval.Speed = Rand(1,Fields_arg)
			NewOval.Shade = ( (200/Fields_arg)*NewOval.Speed ) + 55
			NewOval.Scale = (1.0 / 255)*NewOval.Shade
			ListAddLast OvalList,NewOval
		Next
		SortList(OvalList, True, CompareSpeed)		
	End Function
	
	Function Update()
		SetBlend MASKBLEND
		For Local CurrentOval:Oval = EachIn OvalList
			CurrentOval.XPos = CurrentOval.XPos - CurrentOval.Speed
			If CurrentOval.XPos < -OVAL_SIZE Then CurrentOval.XPos:+GWIDTH+OVAL_SIZE	
			CurrentOval.Draw()
		Next
	End Function

	Function CompareSpeed:Int(ObjectA_arg:Object, ObjectB_arg:Object)
		If Oval(ObjectA_arg).Speed > Oval(ObjectB_arg).Speed
			Return True
		Else
			Return False
		EndIf		
	End Function
End Type

Type Oval
	Field XPos:Int
	Field YPos:Int
	Field Shade:Byte
	Field Speed:Byte
	Field Scale:Float
	
	Method Draw()
		SetColor Self.Shade,Self.Shade,Self.Shade
		SetScale Self.Scale,Self.Scale
		DrawImage OvalField.OvalPic, Self.XPos, Self.YPos 
	End Method
End Type


Thanks both, very usefull code, now i get it, thanks again.