无法从 eclipse 插件项目包中获取图像文件 URL
Unable to get Image file URL from eclipse plugin project Bundle
我正在尝试从 eclipse 插件项目中的包中获取图像。但它总是 return null。请在下面找到项目结构。我想获取 "images/EmailTemplatesOutput/assets/icon_4.png" 下的图像 "icon_4.png" 的 URL。我尝试了不同的方法。但它 return 无效。
项目结构是:
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/EmailTemplatesOutput/assests/icon_4.png
(假设您移动了图像目录)。
FileLocator.find
返回的 URL 使用仅限 Eclipse 的方案,因此只能由 Eclipse API 使用。您可以通过添加以下内容将 URL 转换为普通文件 URL:
URL fileURL = FileLocator.toFileURL(url);
这可能会导致 Eclipse 将您的插件解压缩到一个临时位置以访问这些文件。
我正在尝试从 eclipse 插件项目中的包中获取图像。但它总是 return null。请在下面找到项目结构。我想获取 "images/EmailTemplatesOutput/assets/icon_4.png" 下的图像 "icon_4.png" 的 URL。我尝试了不同的方法。但它 return 无效。
项目结构是:
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/EmailTemplatesOutput/assests/icon_4.png
(假设您移动了图像目录)。
FileLocator.find
返回的 URL 使用仅限 Eclipse 的方案,因此只能由 Eclipse API 使用。您可以通过添加以下内容将 URL 转换为普通文件 URL:
URL fileURL = FileLocator.toFileURL(url);
这可能会导致 Eclipse 将您的插件解压缩到一个临时位置以访问这些文件。