>From my experiments, that last example wont work.

final Image image = new Image(mapResources.map());

That line makes GWT try to use a sprite sheet, making the <img> use
style="background:" to display the image. Such an Image won't be shown
when drawn on the canvas. I have to force gwt to use the src="" by
doing:

final Image image = new Image(mapResources.map().getURL());

I guess the proper solution would be to have GWT export the sprite
sheets it generates, and then use the proper canvas draw method to
draw that portion of the sheet.

On Feb 6, 6:10 pm, Dallas <[email protected]> wrote:
> I've been looking into this same problem and what I've found is a
> couple of issues.
>
> First being that you are not loading the image (ie. not pulling the
> image from the server), only setting the image properties (eg. url,
> width, height, etc), so in order to do what you want you would have to
> call the drawImage in a LoadHandler event:
>
> final Image image = new Image(mapResources.map());
> image.addLoadHandler(new LoadHandler() {
>         @Override
>         public void onLoad(LoadEvent event) {
>                 final ImageElement e = ImageElement.as(image.getElement());
>                 contextMap.drawImage(e, x, y);
>         }
>
> });
>
> But this now leads to the second problem - what's going to call the
> load?  The only solution I've come up with thus far is subsequently
> adding a RootPanel.get().add(image) which adds the image to the DOM
> which in turns loads up the image.  From there I simply added an
> 'image.removeFromParent' line in the onLoad method.
>
> final Image image = new Image(mapResources.map());
> image.addLoadHandler(new LoadHandler() {
>         @Override
>         public void onLoad(LoadEvent event) {
>                 final ImageElement e = ImageElement.as(image.getElement());
>                 contextMap.drawImage(e, x, y);
>                 image.removeFromParent();
>         }});
>
> RootPanel.get().add(image); // triggers the image load
>
> But this solution is hardly ideal.  I understand that unless the image
> is part of the DOM, the image isn't technically part of the hosting
> page, which is why it will not load/show.
>
> The idea of an image preloader is probably the way to go, I'm going to
> look into this myself.  There was the ImageLoader helper class from
> the gwt incubator that I had previously used, but it didn't fit well
> with the ClientBundle concept, and I don't think it survived the move
> into the 2.2 branch.
>
> On Feb 6, 10:46 am, Jambi <[email protected]> wrote:
>
>
>
>
>
>
>
> > Hej Thomas,
>
> > it´s the same with your solution. The Image won´t appear on the
> >canvas. Maybe it is a bug since thecanvasapi is still experimental?
> > Maybe I should try a different approach to implement an image
> > preloader.
>
> > On Feb 6, 11:50 am, Thomas Broyer <[email protected]> wrote:
>
> > > Or, without creating an Image widget:
> > > AbstractImagePrototype.create(imageResource).createElement()

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.

Reply via email to