Image size

13 views
Skip to first unread message

hezjing

unread,
Apr 29, 2009, 10:36:06 AM4/29/09
to gwt
Hi

I have the following code snippet,

        Image logo = new Image("images/logo.png");
        logo.setSize("153px", "14px");


The logo.png has the size of 153 x 14, and I have to specify this size before adding to a FlowPanel.
Otherwise, the image will be resized (scratched to bigger size) automatically and become ugly.

Can GWT takes the image size automatically without having us to specify them?
It's going to be tedious with several images.


Thank you!


--

Hez

alex.d

unread,
Apr 30, 2009, 2:22:46 AM4/30/09
to Google Web Toolkit
Shouldn't be this way - i'm using a lot of images and i'm certainly
not setting their sizes manually. Does this occur only with a
flowpanel? Can you make a small example that demonstrates the problem?

hezjing

unread,
May 1, 2009, 4:33:30 AM5/1/09
to Google-We...@googlegroups.com
Hi Alex,

On Thu, Apr 30, 2009 at 2:22 PM, alex.d <alex.du...@googlemail.com> wrote:

Shouldn't be this way - i'm using a lot of images and i'm certainly
not setting their sizes manually. Does this occur only with a
flowpanel? Can you make a small example that demonstrates the problem?


Then, there must be something I did wrong.

Here is the sample code:

    public void onModuleLoad() {

        // logo.png is a 153x14 pixel image.
        Image logo = new Image("images/logo.png");

        // VerticalPanel p = new VerticalPanel();
        // HorizontalPanel p = new HorizontalPanel();
        FlowPanel p = new FlowPanel();
        p.add(logo);

        RootPanel root = RootPanel.get();
        root.add(p);
    }


When tested in hosted mode, the image is being scratched and resized.


Thanks for your help!


--

Hez

denis56

unread,
May 1, 2009, 1:14:52 PM5/1/09
to Google Web Toolkit
i also saw image being scaled in IE (not in Firefox) when added to a
Grid widget. solved through setting size manually as well.

On May 1, 10:33 am, hezjing <hezj...@gmail.com> wrote:
> Hi Alex,

hezjing

unread,
May 4, 2009, 12:40:06 PM5/4/09
to Google-We...@googlegroups.com
Hi

I just upgrade my browser to IE8 and the image doesn't scale anymore without specifying the size.
It seems that the image will scale in IE7 if we don't specify the size explicitly.


denis56, are you using IE7 too?
--

Hez

denis56

unread,
May 5, 2009, 1:55:47 PM5/5/09
to Google Web Toolkit
IE 6 (

X

unread,
May 5, 2009, 9:29:30 PM5/5/09
to Google-We...@googlegroups.com
If you want IE7 amd IE8, look into virtualbox.  Microsoft gives away FREE vhd harddrives online with XP+IE6, XP+IE7, XP+IE8, VISTA+IE7 and VISTA+IE8.  Of course, they only last a few months at a time, but they're free for web developer testing.  {Sets up on Ubuntu real nice}

Anyway...  I've been known to use some trickery in getting Images to size correctly on all browsers.  I use server-side image resizing to take a maxWidth and maxHeight {via url, mod rewrite and an image sizing library from http://shiftingpixel.com/2008/03/03/smart-image-resizer/}, shrink or grow the image to the first max value, spit it into the browser at opacity=0.01, measure it to determine the supplied aspect ration, and adjust the maxW/H size values so I can define absolute sizes on scaled objects without trying to trick each rendering engine to NOT pixelate the %~^@# out of my images.  Basically, the W/H are just doubles between 0 and 1, and the ratio adjustment makes one or the other a little closer to zero by multiplying by ((double)actualW/actualH).  It gets sized on screen by multiplying the 0->1 coords by current screen width or height.

Since I doubt you really want to take the time tweaking the image resizer from shiftingpixel, implmenting my scary graphics threads, or my xml->js JSOs, I recommend using the "make image object, set opacity to 0.01, add to document, Deferred Wait, set Src, poll for images to have size, measure actual size, adjust ui, delete original image element {store info in a widget or static list}."


--
"He whose desires are drawn toward knowledge in every form will be absorbed in the pleasures of the soul, and will hardly feel bodily pleasure --I mean, if he be a true philosopher and not a sham one." - Plato
"Wise Words Wover With Will Wakes Worlds" - Alyxandor Artistocles
Reply all
Reply to author
Forward
0 new messages