permaculture playing cards*
The moose likes Other Open Source Projects and the fly likes How to create a jpeg image using jasperreport? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "How to create a jpeg image using jasperreport?" Watch "How to create a jpeg image using jasperreport?" New topic
Author

How to create a jpeg image using jasperreport?

garfild Baram
Ranch Hand

Joined: Mar 24, 2003
Posts: 60
Hi,
Does anyone knows how to create a jpeg image using jasperreport object?

Thanks

Jo
garfild Baram
Ranch Hand

Joined: Mar 24, 2003
Posts: 60
I have found the way and it works great.

I get the image by using:

JasperPrint print = JasperFillManager.fillReport(Compiled_file, parameters, new JRTableModelDataSource(new JRStickerDataSource(stickers,0)));
Image image = JasperPrintManager.printPageToImage(print, 0, 2.0f);


private void createJpeg(Image image,String imageName){
try{
MediaTracker mediaTracker = new MediaTracker(new Container());
mediaTracker.addImage(image, 0);
mediaTracker.waitForID(0);
// determine thumbnail size from WIDTH and HEIGHT
int thumbWidth = Integer.parseInt("90");// size in pixels
int thumbHeight = Integer.parseInt("80");//size in pixles
double thumbRatio = (double)thumbWidth / (double)thumbHeight;
int imageWidth = image.getWidth(null);
int imageHeight = image.getHeight(null);
double imageRatio = (double)imageWidth / (double)imageHeight;
if (thumbRatio < imageRatio) {
thumbHeight = (int)(thumbWidth / imageRatio);
} else {
thumbWidth = (int)(thumbHeight * imageRatio);
}
// draw original image to thumbnail image object and
// scale it to the new size on-the-fly
BufferedImage thumbImage = new BufferedImage(thumbWidth,thumbHeight, BufferedImage.TYPE_INT_RGB);
Graphics2D graphics2D = thumbImage.createGraphics();
graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION,RenderingHints.VALUE_INTERPOLATION_BILINEAR);
graphics2D.drawImage(image, 0, 0, thumbWidth, thumbHeight, null);
// save thumbnail image to OUTFILE
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream("C:\\" +imageName + ".jpg"));
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(thumbImage);
param.setQuality(1.0f, false); // Best quality - 1.0f, Lowest quality - 0.0f
encoder.setJPEGEncodeParam(param);
encoder.encode(thumbImage);
out.close();
}
catch(Exception ex){
logger.error("Jasper Error:\n"
+"Check if the jrxml file is the right one or check that the parameters names idetical.\n"
+"System message - " + ex.getMessage());
}
}

Good luck

Jo
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to create a jpeg image using jasperreport?
 
Similar Threads
how to use jasperreport using netbean
How to create a new image file?
Write layouts to the bitmap file
load a jpeg 2000 image
Creating image jpeg file from a image object