Twitter github

Resizing Images using SWT

I was toying with ECF today along with those new fancy custom tooltips.

In the process of doing this, I was dealing with images obtained from google’s GTalk server and they were coming back in crazy shapes and sizes. I thought to myself, it can’t be that hard to resize images, lo’ and behold… it really isn’t… here’s a code snippet to do it (may not be the best way, but it works):


private Image resize(Image image, int width, int height) {
Image scaled = new Image(Display.getDefault(), width, height);
GC gc = new GC(scaled);
gc.setAntialias(SWT.ON);
gc.setInterpolation(SWT.HIGH);
gc.drawImage(image, 0, 0,
image.getBounds().width, image.getBounds().height,
0, 0, width, height);
gc.dispose();
image.dispose(); // don't forget about me!
return scaled;
}

Now all I need to figure out is how to make those new fancy custom tooltips even better. I have a usecase where I want a user to click that tooltip, if so, leave the tooltip open and allow the user to click possible hyperlinks and close it manually later on. The reason I want to do this is because I want to allow people like the Mylyn folks maybe to plug something in where they could have a hyperlink to show relevant tasks on a user.