Reputation: 39
The scaleImage="RetainShape"
works correctly for a larger image but for a smaller image, it enlarges(stretches, hampering the image quality) it as per either by width or height of the report element .
<image scaleImage="RetainShape" hAlign="Center" vAlign="Middle">
<reportElement x="10" y="10" width="534" height="300"
<imageExpression><![CDATA[$P{originalImage}]]></imageExpression>
</image>
Can we set the scaleImage
property Dynamically? If (image is large) scaleImage="RetainShape"
else scaleImage="Clip"
Upvotes: 1
Views: 310
Reputation: 39
For those who are searching answers for similar scenarios... So as Alex suggested, I created a conditional style and applied it to the image tag
<style name="scaleImageStyle" hImageAlign="Center" vImageAlign="Middle">
<conditionalStyle>
<conditionExpression><![CDATA[$P{originalImage}.getHeight(null) <=300]]></conditionExpression>
<style scaleImage="Clip"/>
</conditionalStyle>
<conditionalStyle>
<conditionExpression><![CDATA[$P{originalImage}.getHeight(null) >300]]></conditionExpression>
<style scaleImage="RetainShape"/>
</conditionalStyle>
</style>
<image hAlign="Center" vAlign="Middle">
<reportElement style="scaleImageStyle" isPrintRepeatedValues="false" x="0" y="0" width="535" height="300" uuid="d813ec39-6f47-4361-9d82-c312924c2ba0"/>
<imageExpression><![CDATA[$P{originalImage}]]></imageExpression>
</image>
Upvotes: 1