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