How to use Images in an Eclipse plugin? [message #67276] |
Fri, 20 May 2005 23:29  |
Eclipse User |
|
|
|
Originally posted by: chibacity.gmail.com
Hi,
I've used some example code from the following article on www.eclipse.org
Using Images in the Eclipse UI (Revised for 2.0)
The method in question is:
private Image getIconImage(String name)
{
String iconPath = "icons/";
ImageDescriptor descriptor = null;
try {
URL installURL =
SubethaclipsePlugin.getDefault().getDescriptor().getInstallU RL();
URL url = new URL(installURL, iconPath + name);
descriptor = ImageDescriptor.createFromURL(url);
} catch (MalformedURLException e) {
System.err.println("MalformedURLException: " + e.getMessage());
return null;
}
return descriptor.createImage();
}
While this seems to work, the following are deprecated:
The method getDescriptor() from the type Plugin is deprecated
The method getInstallURL() from the type IPluginDescriptor is deprecated
I'm hoping someone can give me a hint as to what is the suggested way of
creating an Image object given a "gif" file located within the project. I'm
by no means an expert in the Eclipse framework, hence my turning to the
article in the first place for some example code.
Thanks in advance!
Regards,
Ben
|
|
|
Re: How to use Images in an Eclipse plugin? [message #67288 is a reply to message #67276] |
Fri, 20 May 2005 23:57  |
Eclipse User |
|
|
|
Originally posted by: chibacity.gmail.com
I found another post with a solution to this. Here is the example:
MyPlugin plugin extends AbstractUIPlugin
String relativeURL = "icon/myimage.png"
Image image = plugin.getImageRegistry().get( relativeURL );
if ( image == null ) {
URL imageURL = plugin .getBundle().getEntry( relativeURL );
ImageDescriptor descriptor = ImageDescriptor.createFromURL(imageURL);
Image image = descriptor.createImage();
plugin.getImageRegistry().put( relativeURL , image );
}
"Ben" wrote in message news:d6ma0o$926$1@news.eclipse.org...
> Hi,
>
> I've used some example code from the following article on www.eclipse.org
>
> Using Images in the Eclipse UI (Revised for 2.0)
>
> The method in question is:
>
> private Image getIconImage(String name)
> {
> String iconPath = "icons/";
> ImageDescriptor descriptor = null;
>
> try {
> URL installURL =
> SubethaclipsePlugin.getDefault().getDescriptor().getInstallU RL();
> URL url = new URL(installURL, iconPath + name);
> descriptor = ImageDescriptor.createFromURL(url);
> } catch (MalformedURLException e) {
> System.err.println("MalformedURLException: " + e.getMessage());
> return null;
> }
>
> return descriptor.createImage();
> }
>
> While this seems to work, the following are deprecated:
>
> The method getDescriptor() from the type Plugin is deprecated
> The method getInstallURL() from the type IPluginDescriptor is deprecated
>
> I'm hoping someone can give me a hint as to what is the suggested way of
> creating an Image object given a "gif" file located within the project.
> I'm by no means an expert in the Eclipse framework, hence my turning to
> the article in the first place for some example code.
>
> Thanks in advance!
>
> Regards,
> Ben
>
>
>
|
|
|
Powered by
FUDForum. Page generated in 0.69119 seconds