Is it safe to delete an ImageGadget image after setting it?
Posted: Fri Oct 11, 2019 9:08 am
Are there any issues deleting an image used by ImageGadget() and ButtonImageGadget()? Or it been blitted elsewhere and the original image is safe to release?
I know that a modified image will not display any changes until a new call to SetGadgetState() is made, even if it's to the same image.
I wrote a demo application which mimics my use case; I have a pre-rendered image which I copy and modify every time I want to update an image gadget. Once the gadget has been updated, I no longer need the modified image. Is it OK to just free the image immediately after setting it to the gadget or are there any issues with this that I just haven't encountered?
THE FOLLOWING CODE HAS MULTIPLE COLORS BLINKING AT 200MS (5-times a second). CHANGE IT TO SOMETHING SLOWER IF YOU THINK THIS MIGHT TRIGGER A SEIZURE
I tested this only on Windows 10.
Example:
I know that a modified image will not display any changes until a new call to SetGadgetState() is made, even if it's to the same image.
I wrote a demo application which mimics my use case; I have a pre-rendered image which I copy and modify every time I want to update an image gadget. Once the gadget has been updated, I no longer need the modified image. Is it OK to just free the image immediately after setting it to the gadget or are there any issues with this that I just haven't encountered?
THE FOLLOWING CODE HAS MULTIPLE COLORS BLINKING AT 200MS (5-times a second). CHANGE IT TO SOMETHING SLOWER IF YOU THINK THIS MIGHT TRIGGER A SEIZURE
I tested this only on Windows 10.
Example:
Code: Select all
Procedure drawPattern(imageGadget, image, width)
imageCopy=GrabImage(image,#PB_Any,0,0,132,103)
StartDrawing(ImageOutput(imageCopy))
DrawingMode(#PB_2DDrawing_AllChannels)
For x=0 To width/2-5 Step 10
Box(x,y,width-2*x,width-2*y,RGBA(Random(255),Random(255),Random(255),255))
y+10
Next x
StopDrawing()
SetGadgetState(imageGadget,ImageID(imageCopy))
FreeImage(imageCopy)
EndProcedure
window=OpenWindow(#PB_Any,0,0,132,136,"",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
image=CreateImage(#PB_Any,132,103,32,#PB_Image_Transparent)
imageGadget=ImageGadget(#PB_Any,16,5,132,103,ImageID(image))
buttonGadget=ButtonGadget(#PB_Any,5,109,122,23,"Close")
width=100
drawPattern(imageGadget,image,width)
start=ElapsedMilliseconds()
Repeat
event=WaitWindowEvent(1)
If ElapsedMilliseconds()-start>200
drawPattern(imageGadget,image,width)
start=ElapsedMilliseconds()
EndIf
If event=#PB_Event_Gadget And EventGadget()=buttonGadget
End
EndIf
Until event=#PB_Event_CloseWindow