Jump to content
Changes to the Jaspersoft community edition download ×

HTML/Java2d Export Images Look Terrible

Recommended Posts

By: Hawk - crunchyk9

HTML/Java2d Export Images Look Terrible

2005-03-29 14:37

My images look like they were hit with the ugly stick. They look great in PDF, but when I look at them in HTML or using the JRViewer, the scaling looks terrible.


The images are scaled to about 1/2 their size, and the scaling algorythm both JRViewer and my browser use just mutilate them. Because of my existing asset store, going in and rescaling the images is not an option. I need a way to scale them as the report is being generated, but do it using a better algorythm.


anybody got any ideas?




-- Hawk



By: Doug Berkland - berkland

RE: HTML/Java2d Export Images Look Terrible

2005-03-29 15:52

If you have the algorithm, create a class that exposes the algorithm. (e.g.

package mymagicpackage;

public class MagicImageScaler {

public java.awt.Image scaleImage(String argImageLocation) {

/*magic goes here*/


}). Create an instance of this class and pass it into the report as a parameter (e.g. named "ImageScaler".) In your image field, use the parameter to scale the actual image. (e.g. ((mymagicpackage.MagicImageScaler)$P{ImageScaler}).scaleImage($F{ImageURI}))




By: Hawk - crunchyk9

RE: HTML/Java2d Export Images Look Terrible

2005-03-31 10:47

For anyone else that ends up in this boat:


All I had to do was create a new class which implements JRRenderable. I create an instance of JRImageRenderer and just delegate everthing to it, except render(), which just sets some hints on the graphics context (dithering to off and interpolation to bilinear) and then I just delegate the actual rendering to the JRImageRenderer instance. It's works well. All I have to do is specify my new class name in my .jrxml file.


The HTML was a little nasier. I just extended the JRHtmlExporter and overrode exportImage().


It was much Easier than you'd think. Excellent job teodord, you've really developed a great product.


-- Hawk

Link to comment
Share on other sites

  • 1 year later...
  • Replies 2
  • Created
  • Last Reply

Top Posters In This Topic

I believe I found the solution for my problem. It is like this:

The actual size of the image file is 515 X 287 and We have following statements in JRHtmlExporter:

int imageWidth = image.getWidth() - image.getLeftPadding() - image.getRightPadding();



int imageHeight = image.getHeight() - image.getTopPadding() - image.getBottomPadding();


The caluculated width and height values are used in HTML <img> tag for width and height. This shrinks the actual image size...



I have given padding values to zero in the corrosponding <style> tag in JRXML file as I don't want to change the JRHtmlExporter content.


any comments??




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...