-
FEATURED COMPONENTS
First time here? Check out the FAQ!
How can i show a tiff File in Image object/Control
For example to show pdf (is same to show file like an image jpg, gif, tiff, etc):
if (file.equalsIgnoreCase("PDF")) { showPDF(file); } else { Filedownload fd = new Filedownload(); fd.save(file, content_type, file_name); } where my showPDF is an function public void showPDF(byte[] pdf) { try { Window showpdfWnd = (Window) Executions.createComponents("showpdf.zul", null, null); showpdfWnd.setParent(getWnd()); Iframe iframePdf = (Iframe) showpdfWnd.getFellow("iframePdf"); AMedia media = new AMedia("APP NAME", "pdf", "application/pdf", pdf); iframePdf.setContent(media); showpdfWnd.doModal() } catch (Exception e) { // } } // showpdf.zul <?xml version="1.0" encoding="utf-8"?> <window id="showpdfWnd" width="95%" height="550px" border="normal" title="APP NAME" xmlns:h="http://www.w3.org/1999/xhtml" xmlns:zk="http://www.zkoss.org/2005/zul" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.zkoss.org/2005/zul http://www.zkoss.org/2005/zul/zul.xsd" closable="true"> <zk:iframe id="iframePdf" width="100%" height="100%" /> </window>
Hello. Is late, but I was faced to the same problem and after searching a lot, I saw that there isn't good examples about this problem and I had to read until to find a solution that I wante sharing for the next developer that get the same problem
In the ZUL Page
<image content="@load(vm.bufferImg)"/>
The "image" ZK component supports "BufferedImage" objects, so you should pass your ".tiff" file to an "BufferedImage" object. this snippet of code works for that.
bufferImg = tiffToImage(myTifFile);
public BufferedImage tiffToImage(File file) throws IOException{
FileSeekableStream stream = null;
try {
stream = new FileSeekableStream(file);
ParameterBlock params = new ParameterBlock();
params.add(stream);
RenderedOp image1 = JAI.create("tiff", params);
return image1.getAsBufferedImage();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally{
if(stream != null)
stream.close();
}
return null;
}
Asked: 2008-08-28 09:03:46 +0800
Seen: 343 times
Last updated: Feb 24 '17