Creating an animation image

BlitzMax Forums/BlitzMax Programming/Creating an animation image

MACCB(Posted 2013) [#1]
I am working on a project and want to create an animation image using the grabimage. But I keep getting a unexpect NULL value error. Can anyone tell me where I am going wrong with this code.

Help gratefully received.


M

[Codebox]
'This is me seeting up a BIG IMAGE to grab the entire images in grid 12 x 12, 48 x 48 pixels
Global imageOBJECT:TImage=CreateImage(576,576,1,DYNAMICIMAGE|MASKEDIMAGE)
'This is my image for making bigger image - ignore this not part of the problem
Global imageMAKEOBJECT:TImage=CreateImage(48,48,1,DYNAMICIMAGE|MASKEDIMAGE)

'This is creating a test BIG image and works
Cls
For Local x%=0 To 11
For Local y%=0 To 11
SetColor 120+Rand(0,120),0,0
DrawRect 680,50,48,48
SetColor 120,120,0
DrawText (x*12)+y,686,56
GrabImage imageMAKEOBJECT,680,50
SetColor 255,255,255
DrawImage imageMAKEOBJECT,x*48,y*48
Next
Next
'THIS IS THE BIT THAT WILL NOT WORK
'I AM TRYING TO GRAB THE BIG IMAGE AND THEN TURN INTO ANIMATION IMAGE
GrabImage imageOBJECT,0,0
Global imageALLOBJECTS:TImage=LoadAnimImage(imageOBJECT,48,48,0,143)
Flip

' WHEN I TRY TO TEST IT USING THIS IT BRINGS BACK NULL

While Not KeyHit(Key_Escape)
Cls
DrawImage imageALLOBJECTS,Rand(0,100),Rand(0,100),Rand(0,10)
Flip
Wend

End

[/Codebox]


GNS(Posted 2013) [#2]
It's most likely throwing an error because the 'url' parameter of LoadAnimImage() is expected to be either a string (pointing to a file on the disk) or a TPixmap. You're passing in a TImage so LoadAnimImage() will return NULL which means imageALLOBJECTS=NULL.

Change the imageALLOBJECTS:TImage=... line to:

Global imageALLOBJECTS:TImage=LoadAnimImage(LockImage(imageOBJECT), 48, 48, 0, 143)


MACCB(Posted 2013) [#3]
GNS you are a star! That works great.


MACCB(Posted 2013) [#4]
Just to tidy things up how do I clear imageObject from memory once I have used it in the loadanimimage?

Thanks

M


GNS(Posted 2013) [#5]
imageOBJECT = Null