tags:

views:

2015

answers:

1

Is there any GWT widget which allows me to:

  • select a part of an image and then retrieve the selection area?
  • resize an image and then give me the updated size?

The above should be reflected in the browser as well.

+2  A: 

As far as I know, GWT client-side code cannot directly modify images, but the Image widget can be set to display only a portion of an image. You can do this using the constructor Image(java.lang.String url, int left, int top, int width, int height), where width and height are the dimensions of the visible box and not the image itself.

However this does not allow you to resize and then crop. In order to do this you could first resize the image then put it in an absolute panel to crop it.

AbsolutePanel testPanel = new AbsolutePanel();
Image image = new Image("path/image.jpg");
image.setWidth("1000px");
testPanel.add(image,-100,-100);
testPanel.setPixelSize(300,300);

I apologize if this isn't exactly what you're looking for, but it's the best answer I have.

DLH
This is part of what I'd like to do, but the selection should be based on user action, like what happens in e.g. Photoshop.
Robert Munteanu
Well if you want the user to be able to enter crop values into text boxes, you can use a ChangeHandler to update the Image's position and the panel's size to whatever the values of the text boxes are. If you want the user to be able to drag a box around and have it crop based on the dimensions of that box, you'll probably need a drag 'n drop library.
DLH