Page 1 of 1

Can I delete an image after adding it to the ImageGadget?

Posted: Thu Jun 05, 2025 6:51 am
by Lebostein
Or does the image have to be available with its ImageID as long as I want to display it in the ImageGadget?

Re: Can I delete an image after adding it to the ImageGadget?

Posted: Thu Jun 05, 2025 8:01 am
by Jacobus
Hi Lebostein,
You can find some useful functions for image management in ImageGadget() and more here:
viewtopic.php?t=85730
This should help you

Re: Can I delete an image after adding it to the ImageGadget?

Posted: Thu Jun 05, 2025 10:20 am
by Caronte3D
Lebostein wrote: Thu Jun 05, 2025 6:51 am Or does the image have to be available with its ImageID as long as I want to display it in the ImageGadget?
If you don't want to use the image later (beside of the ImageGadget), I think you can free the image without problem, but it's not needed.

Re: Can I delete an image after adding it to the ImageGadget?

Posted: Thu Jun 05, 2025 12:11 pm
by breeze4me
It seems that an image should not be removed on Windows.
Instead of using RedrawWindow, you can move the window to an offscreen area and then move it back and see that both images have been erased.

Code: Select all

If OpenWindow(0, 0, 0, 245, 105, "ImageGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  If LoadImage(0, #PB_Compiler_Home + "examples/sources/Data/Map.bmp")
    ImageGadget(0,  10, 10, 100, 83, ImageID(0))                     ; imagegadget standard
    ImageGadget(1, 130, 10, 100, 83, ImageID(0), #PB_Image_Border)   ; imagegadget with border
    
    FreeImage(0)
    
    RedrawWindow_(WindowID(0), 0, 0, #RDW_ERASENOW | #RDW_UPDATENOW | #RDW_INVALIDATE | #RDW_ALLCHILDREN | #RDW_ERASE)
  EndIf
  
  Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf

Re: Can I delete an image after adding it to the ImageGadget?

Posted: Thu Jun 05, 2025 12:17 pm
by minimy
Hello, i think the solution is canvasgadget. Can draw the image in a canvas. Delete the image no give error.

Re: Can I delete an image after adding it to the ImageGadget?

Posted: Thu Jun 05, 2025 1:22 pm
by Fred
If it works on Linux and MacOS, there is an inconsistency here and the image should be duplicated on Windows as well.