You don't call Fl_ImageDelete why ?D.J.Peters wrote:You have to delete a Fl_Image (result of Fl_Shared_ImageCopy) with Fl_ImageDelete
Joshy
Code: Select all
#Include "fltk-c.bi"
sub ReleaseSharedImages
var nImages = Fl_Shared_ImageNumImages()
while nImages>0
Fl_Shared_ImageRelease Fl_Shared_ImageImages()[nImages-1]
nImages = Fl_Shared_ImageNumImages()
wend
end sub
sub SetImage(box As FL_Widget Ptr,filename as zstring ptr,w as long,h as long)
ReleaseSharedImages
var img = Fl_WidgetGetImage(box)
if img then
Fl_WidgetSetImage box,0 ' remove image from widget
Fl_ImageDelete img ' free the image
end if
' load, copy and scale a new image
img = Fl_Shared_ImageCopy2(Fl_Shared_ImageGet(filename),w,h)
if img then Fl_WidgetSetImage box,img ' set image to widget
Fl_WidgetRedraw Fl_WidgetWindow(box) ' triger a window redraw (the parent from box)
end sub
Sub JPG_CB Cdecl (byval self As FL_Widget Ptr,byval box as any ptr)
SetImage(box,"media/renata.jpg",64,64)
End Sub
Sub BMP_CB Cdecl (byval self As FL_Widget Ptr,byval box as any ptr)
SetImage(box,"media/renata.bmp",90,90)
End Sub
'
' main
'
chdir exepath() ' make it as current path
Fl_Register_Images() ' prepare all image loaders
var win = Fl_WindowNew (200, 110, "TEST")
var box = Fl_BoxNew(84,10,90,90)
Fl_WidgetSetCallbackArg Fl_ButtonNew (10,10, 64, 24, "JPG"),@JPG_CB,box
Fl_WidgetSetCallbackArg Fl_ButtonNew (10,40, 64, 24, "BMP"),@BMP_CB,box
Fl_WindowShow win
BMP_CB 0,box ' first call !
Fl_Run