My favorites | Sign in
Google
                
Search
for
Updated Feb 25, 2008 by gwt.team.jaimeyap
ImageLoader  
Loader class which invokes a callback when the specified image resources are finished loading in the browser.

Code Examples

The following example shows how ImageLoader can be used with GWTCanvas to draw images with transformations.

Drawing an image (Scaling THEN translating before drawing).

Please note that you must put all drawing code involving the image in the supplied callback. Drawing order for images and paths is guaranteed only within the callback method when working with images (since they have to be loaded first, and it can not be known ahead of time how long that will take).

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.widgetideas.graphics.client.GWTCanvas;
import com.google.gwt.widgetideas.graphics.client.ImageHandle;
import com.google.gwt.widgetideas.graphics.client.ImageLoader;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class MyEntryPoint implements EntryPoint {

  public void onModuleLoad() {
    // Make a new canvas 400x400 pixels
    final GWTCanvas canvas = new GWTCanvas(400,400);
    
    String[] urls = new String[] {"gwt_logo.jpg"};
    
    ImageLoader.loadImages(urls, new ImageLoader.CallBack() {

      public void onImagesLoaded(ImageHandle[] imageHandles) {
        ImageHandle img = imageHandles[0];
        
        canvas.translate(40, 40);
        canvas.scale(0.5f, 0.5f);
        canvas.drawImage(img, 0, 0);
        
      }
      
    });
   
    RootPanel.get().add(canvas);
  }

}

Comment by jorge.lanza, Aug 28, 2009

In version for 1.7 ImageHandle? has been replaced by ImageElement?

Comment by braydw, Sep 04, 2009

I have spent hours trying to get drawImage() to work. I changed ImageHandle? to ImageElement? as per the comment but onImagesLoaded() never executes. Any help would be MUCH appreciated. I am using ver 1.7. I love GWT but unless I can get drawImage() to work it will not be useful to me. --David

Comment by rmcdo...@gmail.com, Dec 08 (6 days ago)

I'm having the same problems (onImagesLoaded() never executes). I see there's a bug logged for this but a comment afterwards says the submitter found that it was there problem.

This seems to be a common issue. I suspect it's something that we've done wrong but since multiple people have encountered the issue it might be a good idea to document it here. If someone has a solution, please post it here. - Rob


Sign in to add a comment