Is there a better way to reset a picture?

Hello All,

I have a picture that is loaded onto a canvas during startup. During program use, it may become desirable to “refresh” the image.

I worked on this for 2 hours, and kind of gave up. To solve it for the moment, I created a new method that would load a blank image, refresh the canvas, then draw the original image followed again, by a refresh.

This works, but I thought maybe someone has a better idea than brute force!

Dim p As String = “e:\temp\blank.jpg”
Dim f As FolderItem = GetFolderItem(P)
If f<> Nil Then
mImage = Picture.Open(f)
End If

frmMain.Canvas1.Refresh

p = trim(App.ManageGraphiX.BackgroundImagePath) + Trim(App.ManageGraphiX.BackgroundImage)
f = GetFolderItem(P)
If f<> Nil Then
mImage = Picture.Open(f)
End If

frmMain.Canvas1.Refresh

Thanks,
Tim

You can use frmMain.Canvas1.Invalidate

You can also use mImage.Close or Nillify it depending on how you Paint the image… or place it in the Canvas’ Backdrop.

sub class the canvas, add a property for your picture.
in paint event of this subclassed canvas use g.DrawPicture, if this picture property = nil draw something else.
if you use a computed property you can memory the new picture into property and at the same time
invalidate the canvas with .Refresh (old name in Xojo was .Invalidate)
this .Refresh will raise the Paint Event.

i use g.DrawPicture instead of canvas backdrop because backdrop picture property was not scaled.

1 Like

Thank you both,
Will try those suggestions.

Tim