簡體   English   中英

Wicket從Web應用程序目錄外的文件系統創建映像

[英]Wicket create image from file system outside web application directory

我有一個存儲庫,在服務器上的某處存儲了許多圖像。 我希望能夠使用存儲在我的存儲庫中的一個圖像創建一個動態Image對象。

我正在使用wicket 1.5.7。 我在某處看到了這個例子

1)創建了FileResource類:

public class FileResource extends WebResource { 
private static final long serialVersionUID = 1L; 

private File file; 

public FileResource(File file) { 
    this.file = file; 
} 

@Override 
public IResourceStream getResourceStream() { 
    return new FileResourceStream(file); 
} 
}

2)在MyPage.java中:

File imageFile = new File("local_path_to_image"); 
Image myImage = new Image("myImage", new FileResource(imageFile)); 
add(myImage);

3)在MyPage.html中:

<i-m-g wicket:id="myImage" />

但這不適用於我的情況,因為我的wicket 1.5中沒有WebResource。

我也在wicket行動中研究了這個鏈接 但我是一個門徒,我無法理解。

我正在制作一個項目,用戶在點擊產品時打開一個帶有產品名稱的模態窗口。 我還想在面板內的模態窗口中包含產品圖像。 圖像存儲在我的服務器上的目錄中。

任何幫助和建議表示贊賞! 提前致謝。

最后我決定使用這段代碼。 我正在傳遞圖像文件名並創建圖像。

add(new NonCachingImage("imgPlc", new AbstractReadOnlyModel<DynamicImageResource>(){
          @Override public DynamicImageResource getObject() {
            DynamicImageResource dir = new DynamicImageResource() {
              @Override protected byte[] getImageData(Attributes attributes) {
                  StringValue name = parameters.get("name");
                  byte[] imageBytes = null;
                    if(name.isEmpty() == false)
                        imageBytes = getImageAsBytes(name.toString());

                    return imageBytes;
              }
            };
            dir.setFormat("image/png");
            return dir;
          }
        }));

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

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