Let AbstractUIPlugin
handle sharing images with your plugins. It has its own ImageRegistry
that handles storing, disposing, and retrieving of images.
A simple override of initializeImageRegistry(ImageRegistry)
and you are on your way to Image sharing bliss.
public class Activator extends AbstractUIPlugin {
public static final String ID = "rcp.eclipse";
public static final String MY_IMAGE_ID =
"image.myimage";
@Override
protected void initializeImageRegistry(ImageRegistry registry) {
super.initializeImageRegistry(registry);
Bundle bundle = Platform.getBundle(ID);
ImageDescriptor myImage = ImageDescriptor.createFromURL(
FileLocator.find(bundle,
new Path("icons/myImage..gif"),
null));
registry.put(MY_IMAGE_ID, myImage);
}
}
Put your image into workspace/rcp.eclipse/icons/myImage.gif
and then access it in your code.
AbstractUIPlugin plugin = Activator.getDefault();
ImageRegistry imageRegistry = plugin.getImageRegistry();
Image myImage = imageRegistry.get(Activator.MY_IMAGE_ID);