0

I am creating a widget in which a portion of an image will be highlighted and the remaining portion will have an opacity 0.5.

For this i am using two images. The full image at the back with opacity 0.5. the portion of the image i want to be highlighted in the front. the front image is GWT's Clipped image.

I have a scenario where i have to resize the back image. Is there any way to resize the clipped image at the front?

Kasturi
  • 3,335
  • 3
  • 28
  • 42

2 Answers2

2

GWT implements clipped images using CSS2 style (along with a blank image contents), as in the following example:

width: 300px; height: 300px; 
background: url("/team.png") no-repeat scroll -5px -5px transparent;

Unfortunately CSS2 does not support scaling background (url-supplied) images, so there's not a natural way to scale a clipped image using built-in GWT libraries.

One option is to use a canvas, and load an image into it, as described at:
http://code.google.com/p/google-web-toolkit-incubator/wiki/GWTCanvas

Otherwise, your best option may be to either clip or scale (or both) the image on the server. Sorry!

-Bosh

Bosh
  • 8,138
  • 11
  • 51
  • 77
0

One alternative with GWT 2.0+, if you don't mind to serve different images is define a ClientBundle with different DataResources, one for each image. Next you should use the DataResource's url for setting the images' url.

interface MyClientBundle extends ClientBundle {
   @Source("img1.png")
   DataResource myImg1();
   @Source("img2.png")
   DataResource myImg2();
}

private static final MyClientBundle BUNDLE = GWT.create(MyClientBundle.class);

then...

new Image(BUNDLE.myImg1().getUrl());

It should work and GWT can generate "data:" URL's for the browser's that support it, eliminating the need for a separate image download at all.

By the way: do you really need to resize? Visually it's not very nice.

helios
  • 13,574
  • 2
  • 45
  • 55