I have a strange problem with drawing images on Canvas.
When I trying to load image on canvas through, e.g.
Canvas canvas = new Canvas();
canvas.setWidth("400px");
canvas.setHeight("400px");
canvas.clear();
canvas.drawImage("http://www.google.ru/intl/en_com/images/srpr/logo1w.png",50,50);
I see an empty canvas! But if I refresh the page, all is OK. I’ve attempted several different ways to do this , even try to switch the GWTCanvas on gwt-g2d (another Canvas implementation for GWT), it isn’t help. requestRepaintAll() isn’t help too.
Is it possible to force refresh a page somehow? Any ideas?
I’m sorry, but I’m not quite following - there is no Canvas in Vaadin, so I’m going to guess that you’re using some add-on, probably CanvasWidget…?
Did you notice version 1.0.2 fixes some bug with drawImage() (not sure which bug, though, but worth checking out…)
Are you using threads? The browser can’t magically know stuff has changed on the server if the changes occur outside the request, in such cases you need to use poll or push.
Thank you for your advises!
Yes, this is the CanvasWidget, of course.
I use 1.0.2 version, and I don’t use threads.
Just a simple CanvasWidget example:
I’ve checked it with Chrome 6 and Firefox 3.6 - the image shown only after several refreshes.
Seems an image is cached by browser, and only after that it shows correctly.
Apparently you are right, the client-side drawImage method will not draw the image unless it has already been cached. To correct this I added image prefetching to those calls, which should fix the problem. Version 1.0.3 is now
available in the Directory .
I tried use duplicate 3 lines again, but it doesn’t help.
Is there actually other solution for it?
Is this possible to load image from like that ThemeResource into this Canvas? I need image loaded on canvas because I’m doing some operations on this (drawing lines, transparent rectangle).