Probably using ClientBundle wrong but can't figure out what is wrong?

45 views
Skip to first unread message

markww

unread,
Nov 10, 2012, 2:03:06 PM11/10/12
to google-we...@googlegroups.com
Hi,

I'm trying to use ClientBundle with an image. My interface:

    public interface MyImages extends ClientBundle {
        @Source("orange.png")
        ImageResource orange();
    }

The image "orange.png" is in the same package as the above class.

Now I try to use it:

    public void drawCanvas() {
        MyImages resources = GWT.create(MyImages.class);
Image orange = new Image(resources.orange());    
        System.out.println("size: " + orange.getWidth() + ", " + orange.getHeight(); // prints 500x500

        ImageElement ie = ImageElement.as(orange.getElement());
        System.out.println("size: " + ie.getWidth() + ", " + ie.getHeight(); // prints 1x1
        
        canvasContext.drawImage(ie, 0, 0);
    }

The Image instance prints its width/height, correct at 500x500 pixels. I try to convert it to an ImageElement so I can draw it to a canvas, it prints its width as 1x1 pixels. Which is incorrect. So of course, nothing gets drawn to the canvas. 

Am I using ClientBundle wrong? I have other methods for loading/drawing the image which work fine. I just wanted to try this interface out,

Thanks

Alfredo Quiroga

unread,
Nov 10, 2012, 2:06:34 PM11/10/12
to google-we...@googlegroups.com, google-we...@googlegroups.com
When you go to draw try passing orange.getElement()

Sent from my iPhone
--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-web-toolkit/-/xAgxozt0YKkJ.
To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

markww

unread,
Nov 10, 2012, 3:47:33 PM11/10/12
to google-we...@googlegroups.com
Hi,

Context2d.drawImage() wants an ImageElement, but orange.getElement() only produces an Element instance. This is why in the example I had:

     ImageElement.as(orange.getElement());

Thanks


On Saturday, 10 November 2012 14:07:27 UTC-5, Alfredo Quiroga-Villamil wrote:
When you go to draw try passing orange.getElement()

Sent from my iPhone


Hi,

I'm trying to use ClientBundle with an image. My interface:

    public interface MyImages extends ClientBundle {
        @Source("orange.png")
        ImageResource orange();
    }

The image "orange.png" is in the same package as the above class.

Now I try to use it:

    public void drawCanvas() {
        MyImages resources = GWT.create(MyImages.class);
Image orange = new Image(resources.orange());    
        System.out.println("size: " + orange.getWidth() + ", " + orange.getHeight(); // prints 500x500

        ImageElement ie = ImageElement.as(orange.getElement());
        System.out.println("size: " + ie.getWidth() + ", " + ie.getHeight(); // prints 1x1
        
        canvasContext.drawImage(ie, 0, 0);
    }

The Image instance prints its width/height, correct at 500x500 pixels. I try to convert it to an ImageElement so I can draw it to a canvas, it prints its width as 1x1 pixels. Which is incorrect. So of course, nothing gets drawn to the canvas. 

Am I using ClientBundle wrong? I have other methods for loading/drawing the image which work fine. I just wanted to try this interface out,

Thanks

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-web-toolkit/-/xAgxozt0YKkJ.
To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-toolkit+unsub...@googlegroups.com.

Alfredo Quiroga-Villamil

unread,
Nov 10, 2012, 4:37:53 PM11/10/12
to google-we...@googlegroups.com
Interesting, I was on my cell phone before, couldn't check to see but could have sworn that it would take an Element. In any case, if it all fails I guess try then:

ImageElement element = ImageElement.as(image.getElement());
element.setWidth(image.getWidth());
element.setHeight(image.getHeight());

Depending on how involved you need to get with canvas stuff, you might also want to take a look at:

Regards,

Alfredo



To view this discussion on the web visit https://groups.google.com/d/msg/google-web-toolkit/-/xn1JzkTnHvQJ.

To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.



--
Alfredo Quiroga-Villamil

AOL/Yahoo/Gmail/MSN IM:  lawwton


Reply all
Reply to author
Forward
0 new messages