try to use a load handler the getWidth() methods comment says: Gets the width of the image. When the image is in the unclipped state, the width of the image is not known until the image has been loaded (i.e. load event has been fired for the image).
if you just create the Image object and call getWidth() immediately, it cannot know it's width - because the browser has not even loaded it yet It might sometimes work, for images, that the browser already has in it's cache. I didn't actually try it, but it sounds reasonable. On Nov 5, 1:38 pm, Dariusz <[email protected]> wrote: > I have an image lets say 600x800 pixel. Now I want to resize downit to > 60x80 pixel. > > If I use setWidth or setPixelSize( width, height ), then it sometimes > it does it correctly and sometimes not. I've got this problem in both > IE & FF. > > Do I need to do it within a loadHandler()? Or does anyone has a > better solution for it? > > My approach: > > Image thumb = new Image( "C:\path\to\image.jpg" ); > int w = thumb.getWidth(); > int h = thumb.getHeight(); > > int newH = 60; > int newW = ( w * newH ) / h; > if( h > newH ) { > thumb.setPixelSize( newW, newH ); > > } > > Thanks in advance! --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
