Eclipse Plugin: Adding an overlay to an ImageDescriptor

Here’s the class. This will overlay to the bottom right corner.

import org.eclipse.jface.resource.CompositeImageDescriptor;
import org.eclipse.jface.resource.ImageDescriptor;

public class OverlayImageDescriptor extends CompositeImageDescriptor {
private ImageDescriptor imageDescriptor;
private ImageDescriptor overlayImage;
Point size;
Point overlaySize;

public OverlayImageDescriptor(ImageDescriptor imgDescriptor,ImageDescriptor overlayImage) {

protected void drawCompositeImage(int arg0, int arg1) {
drawImage(getImageDescriptor().getImageData(), 0, 0);
ImageData overlayImageData = getOverlayImage().getImageData();
int xValue = size.x-overlaySize.x;
int yValue = size.y-overlaySize.y;;
drawImage(overlayImageData, xValue, yValue);

protected Point getSize() {
return size;

public void setImageDescriptor(ImageDescriptor imageDescriptor) {
this.imageDescriptor = imageDescriptor;
Rectangle bounds = imageDescriptor.createImage().getBounds();
size=new Point(bounds.width,bounds.height);

public ImageDescriptor getImageDescriptor() {
return imageDescriptor;

public void setOverlayImage(ImageDescriptor overlayImage) {
this.overlayImage = overlayImage;
Rectangle bounds = overlayImage.createImage().getBounds();
overlaySize=new Point(bounds.width,bounds.height);

public ImageDescriptor getOverlayImage() {
return overlayImage;



Tags: , , ,

One Response to “Eclipse Plugin: Adding an overlay to an ImageDescriptor”

  1. James Says:

    Thanks for posting this! I’d been searching fruitlessly for something I could use to create overlays without using a Graphics Context with the associated expense of additional Images, and this looks like it’ll about do the trick.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: