[英]Unable to get Image file URL from eclipse plugin project Bundle
我正在尝试从eclipse插件项目中的捆绑包中获取图像。 但是它总是返回null。 请在下面找到项目结构。 我想获取“ images / EmailTemplatesOutput / assets / icon_4.png”下的图像“ icon_4.png”的URL。 我尝试了不同的方法。 但它返回null。
String path = "icon_4.png";
Bundle bundle = Platform.getBundle("BulkDemo");
URL url = FileLocator.find(bundle, new org.eclipse.core.runtime.Path(path), null);
ImageDescriptor imageDesc = ImageDescriptor.createFromURL(url);
Image image = imageDesc.createImage();
不要将“ images”目录放在“ src”文件夹中,而是将其放在项目的顶层(例如“ bin”和“ META-INF”)。 确保更新“ build.properties”以在构建中包括images文件夹。
图像的路径是相对于插件根目录的,因此它将是images/EmailTemplatesOutput/assests/icon_4.png
(假设您移动了图像目录)。
FileLocator.find
返回的URL使用仅Eclipse方案,因此只能由Eclipse API使用。 您可以通过添加以下内容将URL转换为普通文件URL:
URL fileURL = FileLocator.toFileURL(url);
这可能会导致Eclipse将插件解压缩到一个临时位置以访问文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.