簡體   English   中英

無法從eclipse插件項目捆綁中獲取圖像文件URL

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM