Jump to content
Changes to the Jaspersoft community edition download ×

Exporting to image


njrfrens

Recommended Posts

How can I export the chart output of .jasper result as an image?

We have exporters like JRHtmlExporter,pdf,xls,xml etc. but couldn't find any exporter for image. Why is it so?

if not image, atleast can I get the byte array of the result of .jasper? so that I'll convert the byte stream to image...

 

 

Link to comment
Share on other sites

  • Replies 2
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Assuming you already have the jasperprint object

 

 

 

Code:
			        	response.setContentType("image/jpeg");			        				        	BufferedImage pageImage = new BufferedImage(jasperPrint.getPageWidth() + 1, jasperPrint.getPageHeight() + 1, BufferedImage.TYPE_INT_RGB);			        				        	exporter = new JRGraphics2DExporter();			        	exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);			        			                Map imagesMap = new HashMap();		        				                request.getSession().setAttribute("IMAGES_MAP", imagesMap);			        			                exporter.setParameter(JRHtmlExporterParameter.IS_OUTPUT_IMAGES_TO_DIR, Boolean.FALSE);		                exporter.setParameter(JRHtmlExporterParameter.IMAGES_MAP, imagesMap);		                exporter.setParameter(JRHtmlExporterParameter.IMAGES_URI, context+"/images?image=");			        				        	exporter.setParameter(JRGraphics2DExporterParameter.GRAPHICS_2D, pageImage.getGraphics());			        	exporter.setParameter(JRExporterParameter.PAGE_INDEX, new Integer(0));			        				            exporter.exportReport();			            output = bufferedImageToByteArray(pageImage);	      public static byte[] bufferedImageToByteArray(BufferedImage img) throws IOException{	   	      ByteArrayOutputStream os = new ByteArrayOutputStream();	   	      JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(os);	   	      encoder.encode(img);	   	      return os.toByteArray();	   	      }	 
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...