Clearing Canvas content

When using a canvas container for an image, I replace the image based on the cell of a list being checked.
This works fine, as does my resizing script I found here on the forum.

However, when the images are different sizes and rescaled to fit the canvas, the previous image appears in the background
as if the images are stacked.

How do I clear or reset a canvas so that each time an image is set as the background, the previous background is cleared?

Try:

g.ClearRect(0, 0, g.Width, g.Height)

in the paint event

You shouldn’t need to clear the canvas (BTW a canvas is a control, not a container. Terminology is important). In your paint event set branching code (If…Then…Else…Endif) to determine what gets drawn. If you do that, and call canvas1.invalidate each time a change is needed, only one image will be drawn. Likewise, if you don’t draw anything in your canvas, it will be cleared if you call invalidate.

This code puts a resized image into a canvas, but it also puts the original sized image, above all the resized image is overlayed, and I want to delete the original image:

[code] Dim scale As Double
dim p as picture = picture.Open(writeFile1)
dim g as Graphics

lblSize1.text = "Size: " + str(p.Width) + ", " + str(p.height)

cnvFront.backdrop = p
g= cnvFront.Backdrop.Graphics
'g.ClearRect(0, 0, g.Width, g.Height)
scale = cnvFront.width/p.Width
g.DrawPicture( p, 0, 0, p.Width * scale, p.Height * scale, 0, 0, p.Width, p.Height)
g.ForeColor = RGB(0,0,0)
g.pixel(cnvFront.Width/2,cnvFront.Height/2)=RGB(0,0,0)[/code]

How is that possible that the “ClearRect” statements clears the image which is placed in the canvas AFTER, in the FOLLOWING line?!?

You use backdrop, it’s best to don’t do that.
Draw it in a picture as property or so and draw that picture in the paint event.

Basicly you want to call a method to create the picture and in the paint event you want to place it using g.DrawPicture. Whe. The method is called, you call canvas.invalidate

Why ?

In fact, the bad behavior the op complains cannot appears if you use Canvas1.Backdrop = <my_picture>…

Because (takern from the Manual): http://developer.xojo.com/canvas

I do not saw that in the part I asked. Sorry.

Thanks for clarifying.