broschb Posted March 30, 2007 Share Posted March 30, 2007 I have an application in which i am using the JRGraphics2DExporter to export the graphics object of the report. This works and I can see my report, but it appears that the quality of the image returned is very low. The text is pixelated and grainy looking, and when i print it is even worse. Is there anyway to improve the quality. I am using the following to export the Graphics2D Object. Code:BufferedImage image = new BufferedImage( width, height, BufferedImage.TYPE_3BYTE_BGR); Graphics2D graphics = image.createGraphics();try { JRGraphics2DExporter exporter = new JRGraphics2DExporter(); exporter.setParameter( JRGraphics2DExporterParameter.GRAPHICS_2D, (Graphics2D) graphics); exporter.setParameter(JRExporterParameter.JASPER_PRINT, ivrPrint); exporter.setParameter(JRExporterParameter.PAGE_INDEX, i); exporter.exportReport(); } catch (JRException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } Link to comment Share on other sites More sharing options...
michaelzhou Posted April 6, 2007 Share Posted April 6, 2007 Since you BufferedImage is dynamically generated and its image type is unknown, the JasperReports engine will somehow compromise its quality.However, the engine does preserver the quality of the image whose type is known. So saving the bufferedimage temporarily to a known format might solve the issue, this can be achieved as:***************************************ByteArrayOutputStream baos = new ByteArrayOutputStream(); ImageIO.write(image, "png", baos); ByteArrayInputStream inputStream = new ByteArrayInputStream(baos.toByteArray());***************************************Then you wrap up the inputStream and feed it to the report. Michael Link to comment Share on other sites More sharing options...
hem Posted April 6, 2007 Share Posted April 6, 2007 Try BufferedImage image = new BufferedImage( width, height, BufferedImage.TYPE_INT_RGB); Greetings, HeM Link to comment Share on other sites More sharing options...
broschb Posted April 6, 2007 Author Share Posted April 6, 2007 Thanks for the suggestion, I did the following below and received the same results, is this what you were referring to? Code:BufferedImage image = new BufferedImage( width, height, BufferedImage.TYPE_INT_RGB«»); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ImageIO.write(image, "png", baos); ByteArrayInputStream inputStream = new ByteArrayInputStream(baos.toByteArray()); Graphics2D graphics = image.createGraphics(); try { JRGraphics2DExporter exporter = new JRGraphics2DExporter(); exporter.setParameter( JRGraphics2DExporterParameter.GRAPHICS_2D, (Graphics2D) graphics); exporter.setParameter(JRGraphics2DExporterParameter.INPUT_STREAM,inputStream); exporter.setParameter(JRExporterParameter.JASPER_PRINT, ivrPrint); exporter.setParameter(JRExporterParameter.PAGE_INDEX, i); exporter.exportReport(); } catch (JRException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } Link to comment Share on other sites More sharing options...
michaelzhou Posted April 13, 2007 Share Posted April 13, 2007 It seems with your code you are still using your original image object (with the image type unspecified) to create that Graphics2D. Try creating the Graphics2D from the inputStream you have obtained: *************************************************Graphics2D graphics = ImageIO.read(inputStream).createGraphics();************************************************* You probably don't have to worry about the JRGraphics2DExporterParameter.INPUT_STREAM if you have gone through the above code. Cheers,Michael Link to comment Share on other sites More sharing options...
antuansoft Posted May 12, 2014 Share Posted May 12, 2014 I have solved this issue in my answer to this question: Use JasperPrintManagerhttp://community.jaspersoft.com/questions/517024/export-report-image-jpg-bmp-or-any-format Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now