Paint event in WebCanvas.

[code]Sub Paint(g as WebGraphics)
dim t, l as integer
dim op as Picture = OpenPicture
dim cp as Picture = ClosePicture

t = (22 - 16) / 2
l = (22 - 16) / 2

if IsExpanded then
g.DrawPicture(op, l, t)
else
g.DrawPicture(cp, l, t)
end if

End Sub
[/code]

Open And Close Picture are 16x16x32 bit png files, the Canvas is 22x22.
Nothing displays. Have I don’t this wrong?

That looks right. I suggest making your pictures into shared properties though. That way you only load then once for your whole project, instead of every time the paint event fires.

Behind the scenes, a webimageview is created which asks the browser to download the image. Once it gets there, the browser asks for a repaint to get the latest code ( in case it has changed). You may be getting into a situation where the image is never current.

I dragged and dropped the images onto the project. Isn’t that a shared property?

No. The pictures will get converted to WebPicture before being sent to the browser. Every time you draw those pictures, new WebPictures will be created. To reuse the images, you might need to make invisible WebImageViews and draw those instead of pictures. See the LR.

http://documentation.xojo.com/index.php?title=WebGraphics.DrawPicture&oldid=45185

It would be helpful to have a version of WebGraphics.DrawPicture that took a WebPicture as a parameter. Then you’d make the WebPicture a shared property of your WebPage.

I’m really confused.
The draw picture method takes a picture not a WebPicture.
I don’t see how I’m suppose to properly handle the Paint Event, iff that is the place it is meant to be drawn.
Maybe I shouldn’t be using a canvas to ‘hold’ the picture?

So I switched from a canvas to a WebImageView.
Things make a little more sence now…

thanks.

FWIW, because we keep the images around, we check to see if you are drawing the exact same picture, and if you are, we use the WebImageView that we already have.

By the way… Just to make a point… the webcanvas refused to show an image… Maybe there is a bug.
ImageView worked fine.