Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    How to draw images in their actual size

    How can I draw images in their actual size? Going off of this post:
    http://forums.smartclient.com/showth...mage+full+size
    I am doing the following:

    Code:
    		final Img img = new Img(urlToImage);
    		img.setImageType(ImageStyle.NORMAL);
    		img.addDrawHandler(new DrawHandler() {
    			
    			public void onDraw(DrawEvent event) {
    				img.adjustForContent(true);
    			}
    		});
    		layout.addMember(img);
    
    		IButton adjustButton = new IButton("Adjust");
    		adjustButton.addClickHandler(new ClickHandler() {
    			
    			public void onClick(ClickEvent event) {
    				img.adjustForContent(true);
    		}});
    		layout.addMember(adjustButton);
    But the img.adjustForContent is being called before the image is loaded. If I wait tilll the image is done being loaded and click the adjust button it works fine.

    How can I know when the image is done being loaded so I can call the adjustForContent method?

    SmartGWT 2.1, FF

    #2
    I've been playing with FileLoader.cacheImg("", urlToImage) but that too is asynchronous and does not have an onload option.

    Comment


      #3
      Yes it does, the third parameter is a callback.

      Comment


        #4
        According to the javadocs it does not:

        http://www.smartclient.com/smartgwt/javadoc/com/smartgwt/client/util/FileLoader.html#cacheImg%28java.lang.String,%20java.lang.String%29

        Code:
        cacheImg
        
        public static void cacheImg(String skinImgDir,
                                    String baseImageURL)
        
            Cache a list of images
        
            Parameters:
                skinImgDir - the skinImgDir
                baseImageURL - the base urls

        Comment


          #5
          Ah, the underlying SmartClient API does have a callback.

          However, what's simpler here is to use the core GWT Img object.

          Comment


            #6
            Are you recommending I use the underlying SmartClient API or GWT's Image object. Looking at the GWT Image object, it doesn't have an onLoad parameter either.

            Or is there a better way to force images to draw in their natural size?

            Comment


              #7
              The GWT Image object will know the size of images included in your application. For remotely loaded images (eg Yahoo image search), you could use the FileLoader via JSNI, write your own <img onload=""> HTML, or seek out someone's pre-built solution (this isn't a SmartGWT-specific issue).

              Comment

              Working...
              X