Create duplicate image to manipulate

BlitzMax Forums/BlitzMax Beginners Area/Create duplicate image to manipulate

iprice(Posted 2008) [#1]
I've written some code that I thought would duplicate an image and allow the second image to be be written to using WRITEPIXEL.

However, both the original image and the "copy" get written to, rather than just the copy. Obviously image1 and image2 are the same image, but why?




What am I doing wrong?


tonyg(Posted 2008) [#2]
I think your images are sharing the same pixmap pointer and you really should define your variables...



iprice(Posted 2008) [#3]
Thanks again tonyg :)

For such a simple bit of code, I didn't bother with the SuperStrict stuff etc. I know I should - I'm a lazy git at times.


xMicky(Posted 2008) [#4]
Another question in this context:

How can you use WritePixel, ReadPixel if you have an Image with more than one frame, lets say: to have access to frame #1?

I searched the forums but I only found one topic from 2 years ago where is said: pixmaps seem to have an array to store data of animated Images

Field pixmaps:TPixmap[]

But I can't get it to work, it should be something like:

Local image=CreateImage(64, 64, 2)

Local pixmap=LockImage(image)

For x=0 To 63
For y=0 To 63
WritePixel(pixmap.???[1] , x,y , $ffffff00)
Next
Next

Can anyone help?


xMicky(Posted 2008) [#5]
OK, got it: One have to start with
Lockimage(Image, frame)
to get the assigned pixmap of the frame.

SuperStrict
Graphics 640,480

Local image:timage=CreateImage(64,64, 2)

Local pixmap:TPixmap=LockImage(image, 1)

For Local x:Int=0 To 63
For Local y:Int=0 To 63
 WritePixel(pixmap, x,y , $ffffff00)
Next
Next


UnlockImage(image)

Local pixmap2:TPixmap=CopyPixmap(pixmap)

Local image2:timage=LoadImage(pixmap2)

For Local n:Int=0 To 100
 WritePixel(pixmap2,Rand(0,63),Rand(0,63),$ffff000000)
Next

UnlockImage(image2)

DrawImage image,100,100, 1

DrawImage image2,200,200, 0

Flip
WaitKey
End