G.DrawPicture in the Paint Event on Webcanvas

I created a class of type WebCanvas and design in Paint Event.

I created a FOR and take pictures from a property Array of type Picture.

Dim Start As Integer
Dim Left As Integer
For Start=0 to 20
   g.DrawPicture(ListImage(Start),Left,10)

  Left=Left+10
Next

If the property Array “ListImage” there are picture different, the DrawPicture fails to draw them, leaving only some. How can I fix?

Are the images really only 10 pixels wide?

No, the images are width = 150px and height = 150px.

In DrawPicture I set Left = 10px which increases and Top = 10px

But being the images dynamic does not come out all

[quote=145119:@Stefano Basile]Dim Start As Integer
Dim Left As Integer
For Start=0 to 20
g.DrawPicture(ListImage(Start),Left,10)

Left=Left+10
Next[/quote]

If what you want to do is a picture that changes and moves, you cannot do that in one pass within the event. Unlike Desktop, Web Edition UI does not update until the event is over, so the For Next animation will not show.

If you want to do that, you need to place the canvas left change in a timer and call Canvas.Invalidate to update the picture.

The reason why the picture does not show is that when the event finishes, Left is 200. If your canvas is 150, it makes sense.

I have made a small example of what I’m doing
example

Sometimes it comes out well

Other times it comes out badly

Change the array to type WebPicture and make sure the array exists outside of the paint event. I suspect the problem you are running into is that the images are going out of scope before (or not available) when the canvas draws.

Just so you understand this better… An HTML5 canvas requires that the picture exist in the browser’s cache before it can be drawn on the page. What that means is that we can’t acually draw the image in the first event loop after you call the command. What we have to do first is make the browser request each of the images. Each time a the browser downloads an image, we call the Invalidate method so that sometime “soon” the canvas will be refreshed and the canvas will draw. Here’s the trick though… that array of Pictures or WebPictures must not change between paint events. They must persist long enough for the browser to download the image at least once, or the browser will get an error and the image just won’t be displayed.

Anyway, I suspect that the times it works is just happenstance that the browser is able to retrieve the image before it goes away.

If you are still having trouble, create a Feedback inquiry case and attach this sample to it and I’ll take a look at your code.

I have create a Feedback inquiry case:

36863 - G.DrawPicture in the Paint Event on Webcanvas

Leaving a feedback on xojo tell me that is not a bug because I made a code too heavy, uploading images into an array. I have made a very simple example uploading pictures by the project itself, but the g.drawpicture not work.

Example

The first comes out well, repeatedly pressing F5 (to refresh the page), the second is not. I use Windows 7 with Internet Explorer.