Jump to content
We've recently updated our Privacy Statement, available here ×

How can I achieve dynamic image element size?


2004 IR Help

Recommended Posts

By: Manfred Moser - mosabua

How can I achieve dynamic image element size?

2005-09-23 10:59

Hi!

 

I am currently trying to achieve a dynamic image size in a report and I am a bit stuck. Here is what I do and would like to achieve:

 

I have a subreport that has an image field. This field is filled by an io stream containing a png image file. The pixel size of this image should be configurable to the user and therefore is only known at runtime.

 

At this stage I think that there is no way to get the image displayed in the original size whatever it is.

 

The "Retain Shape" scaling makes the image smaller. The "Clip" scaling just cuts it off and the "Fill Frame option fills the image element without changing the size of the element itself. So if the image is larger than the element it actually gets squashed. If the image is smaller empty space stays behind (as far as I understand anyway).

 

I would like another option that changes the image element to the size of the image instead of scaling the image.

 

The only way I think I can achieve this at the moment is to change my report design on the fly, compile it anew with the new size and fill it. That is however a huge overhaul of my architecture since I did not need on the fly report compilation until know.

 

Can I maybe do some adjustment just before I export to PDF? Any other options? Should I launch a feature request?

 

Any help would be awesome.

 

Manfred

Link to comment
Share on other sites

  • 5 months later...
  • Replies 7
  • Created
  • Last Reply

Top Posters In This Topic

I'm having the same problem, where I don't know the size of the image until runtime and I want it to display at its original size.

 

Anyone know if this is possible? I need this for my current project so any reply would be helpful.

 

Thanks!

 

Chris

Post edited by: bogleg20, at: 2007/01/26 21:55

Link to comment
Share on other sites

  • 3 months later...
A bump from me, I am also working on trying to get the image size from the data at report run time. I have considered the modify JasperDesign and recompile option and was also wondering about setting the width and height to java expressions or parameters. If anyone has any insight on this it would be much appreciated.
Link to comment
Share on other sites

Hi,

 

The image element in JR does not adapt its size to the actual image size.

This was added as a feature request here:

http://jasperforge.org/sf/go/artf1404?nav=1

but it would be fairly hard to implement.

 

The only solution right now is to make the image element as big as you think the actual image could be and use scaleImage="Clip". But the problem is that document content would not move around to accommodate the actual image size and you end up having empty space around the image when it is smaller that the maximum size.

 

With reasonable effort, I guess we could make image elements adapt their height to the actual image height, just like text fields do right now when they have isStretchWithOverflow="true". Elements below the image would get pushed if they have positionType="Float".

But what would be difficult to do, given the way JR works, is to make the image also adapt its width. This is because people would expect elements placed at the right of the image to be pushed further to the right, when the image expands to its normal width. No element in JR is able to do that right no and I doubt they will do in the future.

 

Thanks,

Teodor

Link to comment
Share on other sites

  • 1 year later...

Hi.

 

Has this situation changed recently with new releases (maybe the latest version 3.0.0 release; nothing mentioned in changelog) ?

 

 

We are in desperate need for such functionality. After a long investigation in different reporting engines (JR, Crystal, etc.) we decided on Jasper, but the lack of such functionality will probably force us to change our decision 30% into the project! In my opinion this is a basic functionality and therefore it was taken as given by us. :( :unsure:

 

 

Please help!

Regards.

 

PS: The 'project' metioned above is not a normal project with a 'reporting' element to it. It is a custom high level Reporting Engine for a specific Business Domain.

Link to comment
Share on other sites

  • 1 year later...

this works:

Code:
			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"));
Link to comment
Share on other sites

  • 4 years later...
I tried TD idea of using "clip" and a big enough element to accomodate all possible images... ...but i still see images coming out bigger. more specifically, with ireports 3.6.1, and a jpeg that has a width of 281 px, 72 dpi, the html export has an image tag with a width of 496 px. the image in the html export is ok/still 281 px width, but the tag is stretching it to make it bigger. all i need is for the image size to remain unchanged and supporting dynamic images.... ?? any help appreciated much.
Link to comment
Share on other sites

I tried TD idea of using "clip" and a big enough element to accomodate all possible images... ...but i still see images coming out bigger. more specifically, with ireports 3.6.1, and a jpeg that has a width of 281 px, 72 dpi, the html export has an image tag with a width of 496 px. the image in the html export is ok/still 281 px width, but the tag is stretching it to make it bigger. all i need is for the image size to remain unchanged and supporting dynamic images.... ?? any help appreciated much.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...