2010-05-05 48 views
2

我的Java應用程序正在生成碧玉報告的圖像(基本上是組織結構圖)。隨着組織結構圖的推進,人們無法確定圖像輸出的最終大小。此外,圖像輸出可能會變得太大,裁剪圖像無用。在jasper報告中顯示真正巨大的圖像

是否有可能讓碧玉報告動態調整它的圖像元素而不拆分圖像?

回答

1

試試這個:

<image scaleImage="ReatinShape" hAlign="Center"> 
    <reportElement x="100" y="150" width="600" height="150"/> 
    <graphicElement/> 
    <imageExpression class="net.sf.jasperreports.engine.JRRenderable"> 
    <![CDATA[new com.onbarcode.barcode.jasper.JasperRenderer(yourImage)]]></imageExpression> 
</image> 
+0

一個愚蠢的問題... 什麼樣的階級是yourImage參數?這是路徑嗎?或bufferedimage 順便說一句,我習慣於在iReport中開發Jasper報告。 – xilver 2010-05-05 10:49:11

+0

這是您的報告收到的圖像對象作爲輸入。 – 2010-05-05 15:19:00

0

我沒有這個測試自己,但它應該工作。從設計中獲取圖像元素,更改其大小,然後編譯更改後的設計。

BufferedImage img = ImageIO.read(new File(wo_image_path)); 
height = img.getHeight(); 
width = img.getWidth();   
jasperSubDesign = JasperManager.loadXmlDesign(context.getRealPath("/WEB-INF/reports/decoration_sheet_header.jrxml")); 

JRDesignImage image = (JRDesignImage)jasperSubDesign.getPageHeader().getElementByKey("wo_image"); 

image.setX(3); 
image.setY(69); 
image.setHeight(new Long(height - Math.round(height*.35)).intValue()); 
image.setWidth(new Long(width - Math.round(width*.35)).intValue()); 

JasperCompileManager.compileReportToFile(jasperSubDesign, context.getRealPath("/WEB-INF/reports/decoration_sheet_header.jasper")); 

Jasperforge

+0

非常好!我明白這個*可以是一個子報表。如果是這樣,如果圖像實際上超出了報告本身,是否會出現錯誤的可能性? – xilver 2010-05-05 11:48:46

+0

我的猜測是,如果圖像大於報告,編譯將失敗。我不知道Jasper設計API,但你也可以重新調整報告大小。 – Guillaume 2010-05-05 14:10:26