/** * Creates and returns an instance of the JRImageRenderer class after encoding the image object using an image * encoder that supports the supplied image type. * * @param image the java.awt.Image object to wrap into a JRImageRenderer instance * @param imageType the type of the image as specified by one of the constants defined in the JRRenderable interface * @param onErrorType one of the error type constants defined in the {@link OnErrorTypeEnum}. * @return the image renderer instance */ public Renderable getRenderable(Image image, ImageTypeEnum imageType, OnErrorTypeEnum onErrorType) throws JRException { Renderable result; try { result = new JRImageRenderer(JRImageLoader.getInstance(jasperReportsContext).loadBytesFromAwtImage(image, imageType)); } catch (Exception e) { result = handleImageError(e, onErrorType); if (log.isDebugEnabled()) { log.debug("handled image error with type " + onErrorType, e); } } return result; }
public Renderable getOnErrorRenderer(OnErrorTypeEnum onErrorType, JRException e) throws JRException { Renderable renderer = null; switch (onErrorType) { case ICON : { renderer = new JRImageRenderer(JRImageLoader.NO_IMAGE_RESOURCE); //FIXME cache these renderers break; } case BLANK : { break; } case ERROR : default : { throw e; } } return renderer; }
public Renderable getOnErrorRenderer(OnErrorTypeEnum onErrorType, JRRuntimeException e) throws JRRuntimeException { Renderable renderer = null; switch (onErrorType) { case ICON : { renderer = new JRImageRenderer(JRImageLoader.NO_IMAGE_RESOURCE); //FIXME cache these renderers break; } case BLANK : { break; } case ERROR : default : { throw e; } } return renderer; }
/** * */ protected Image getPxImage() { if (pxImage == null) { try { pxImage = Image.getInstance( JRLoader.loadBytesFromResource(JRImageLoader.PIXEL_IMAGE_RESOURCE) ); } catch(Exception e) { throw new JRRuntimeException(e); } } return pxImage; }
/** * Creates and returns an instance of the JRImageRenderer class after encoding the image object using an image * encoder that supports the supplied image type. * * @param image the java.awt.Image object to wrap into a JRImageRenderer instance * @param imageType the type of the image as specified by one of the constants defined in the JRRenderable interface * @param onErrorType one of the error type constants defined in the {@link OnErrorTypeEnum}. * @return the image renderer instance */ public Renderable getRenderable(Image image, ImageTypeEnum imageType, OnErrorTypeEnum onErrorType) throws JRException { byte[] data = null; try { data = JRImageLoader.getInstance(jasperReportsContext).loadBytesFromAwtImage(image, imageType); } catch (Exception e) { if (log.isDebugEnabled()) { log.debug("handled image error with type " + onErrorType, e); } return handleImageError(e, onErrorType); } return SimpleDataRenderer.getInstance(data); }
@Override public void test() { super.test(); numberOfPagesTest(1); try { byte[] imageData = JRImageLoader.getInstance(DefaultJasperReportsContext.getInstance()).loadBytesFromAwtImage(image, ImageTypeEnum.JPEG); JRPrintImage jrImage = (JRPrintImage) getElementAt("title.image1", 0); Assert.assertTrue("image data", Arrays.equals(imageData, jrImage.getRenderable().getImageData(DefaultJasperReportsContext.getInstance()))); Assert.assertEquals("scale image", ScaleImageEnum.CLIP, jrImage.getScaleImageValue()); } catch (JRException e) { e.printStackTrace(); Assert.fail(e.getMessage()); } }
@Override public Image getImage(JasperReportsContext jasperReportsContext) { try { return JRImageLoader.getInstance(jasperReportsContext).loadAwtImageFromBytes( RepositoryUtil.getInstance(jasperReportsContext).getBytesFromLocation(file) ); } catch (JRException e) { throw new JRRuntimeException(e); } }
/** * */ public Image getImage(JasperReportsContext jasperReportsContext) throws JRException { if (awtImageRef == null || awtImageRef.get() == null) { Image awtImage = JRImageLoader.getInstance(jasperReportsContext).loadAwtImageFromBytes(getImageData(jasperReportsContext)); awtImageRef = new SoftReference<Image>(awtImage); } return awtImageRef.get(); }
/** * */ protected Image getImage(JasperReportsContext jasperReportsContext) throws JRException { if (awtImageRef == null || awtImageRef.get() == null) { Image awtImage = JRImageLoader.getInstance(jasperReportsContext).loadAwtImageFromBytes(getData(jasperReportsContext)); awtImageRef = new SoftReference<Image>(awtImage); } return awtImageRef.get(); }
private Renderable getRenderableNoImage(JasperReportsContext jasperReportsContext, JRImage imageElement, JRPrintImage printImage) { try { printImage.setScaleImage(ScaleImageEnum.CLIP); if (noImage == null) noImage = RenderableUtil.getInstance(jasperReportsContext).getRenderable(JRImageLoader.NO_IMAGE_RESOURCE, imageElement.getOnErrorTypeValue(), false); } catch (Exception e) { if (log.isDebugEnabled()) log.debug("Creating icon renderer for converted image failed.", e); } return noImage; }
private Renderable getRenderableNoImage(JasperReportsContext jasperReportsContext, MapComponent map, JRPrintImage printImage) { try { printImage.setScaleImage(ScaleImageEnum.CLIP); if (noImage == null) noImage = RenderableUtil.getInstance(jasperReportsContext).getRenderable(JRImageLoader.NO_IMAGE_RESOURCE, map.getOnErrorType(), false); } catch (Exception e) { e.printStackTrace(); } return noImage; }
/** * Return the standard printable element when the image is not found * * @param jasperReportsContext the context * @param imageElement the actual element * @param printImage the print image * @return return the not printable element */ private Renderable getRenderableNoImage(JasperReportsContext jasperReportsContext, JRImage imageElement, JRPrintImage printImage) { try { printImage.setScaleImage(ScaleImageEnum.CLIP); if (noImage == null) noImage = RenderableUtil.getInstance(jasperReportsContext).getRenderable(JRImageLoader.NO_IMAGE_RESOURCE, imageElement.getOnErrorTypeValue(), false); } catch (Exception e) { e.printStackTrace(); } return noImage; }
/** * */ private TextInputComponentDesignConverter() { super(JRImageLoader.SUBREPORT_IMAGE_RESOURCE);//FIXMEINPUT }
@Override public Renderable getRenderable( JasperReportsContext jasperReportsContext, JFreeChart chart, ChartHyperlinkProvider chartHyperlinkProvider, Rectangle2D rectangle ) { int dpi = JRPropertiesUtil.getInstance(jasperReportsContext).getIntegerProperty(Renderable.PROPERTY_IMAGE_DPI, 72); double scale = dpi/72d; BufferedImage bi = new BufferedImage( (int) (scale * (int)rectangle.getWidth()), (int) (scale * rectangle.getHeight()), BufferedImage.TYPE_INT_ARGB ); List<JRPrintImageAreaHyperlink> areaHyperlinks = null; Graphics2D grx = bi.createGraphics(); try { grx.scale(scale, scale); if (chartHyperlinkProvider != null && chartHyperlinkProvider.hasHyperlinks()) { areaHyperlinks = ChartUtil.getImageAreaHyperlinks(chart, chartHyperlinkProvider, grx, rectangle); } else { chart.draw(grx, rectangle); } } finally { grx.dispose(); } try { return new SimpleDataRenderer(JRImageLoader.getInstance(jasperReportsContext).loadBytesFromAwtImage(bi, ImageTypeEnum.PNG), areaHyperlinks); } catch (JRException e) { throw new JRRuntimeException(e); } }
@Override public byte[] getImageData(JasperReportsContext jasperReportsContext) throws JRException { Dimension2D dimension = getDimension(jasperReportsContext); if (dimension == null) { throw new JRException( EXCEPTION_MESSAGE_KEY_DIMENSION_NULL_NOT_ALLOWED, (Object[])null ); } int dpi = getImageDataDPI(jasperReportsContext); double scale = dpi/72d; ImageTypeEnum imageType = getImageTypeValue(); BufferedImage bi = new BufferedImage( (int) (scale * dimension.getWidth()), (int) (scale * dimension.getHeight()), // avoid creating JPEG images with transparency that would result // in invalid image files for some viewers (browsers) (imageType == ImageTypeEnum.GIF || imageType == ImageTypeEnum.PNG) ? BufferedImage.TYPE_INT_ARGB : BufferedImage.TYPE_INT_RGB ); Graphics2D g = createGraphics(bi); try { g.scale(scale, scale); Color backcolor = getBackcolor(); if (backcolor != null) { g.setColor(backcolor); g.fillRect(0, 0, (int)dimension.getWidth(), (int)dimension.getHeight()); } render(jasperReportsContext, g, new Rectangle((int)dimension.getWidth(), (int)dimension.getHeight())); } finally { g.dispose(); } return JRImageLoader.getInstance(jasperReportsContext).loadBytesFromAwtImage(bi, getImageTypeValue()); }
private GenericElementConverter() { super(JRImageLoader.COMPONENT_IMAGE_RESOURCE); }
/** * */ private SubreportConverter() { super(JRImageLoader.SUBREPORT_IMAGE_RESOURCE); }
private InternalImageProcessorResult processImageClip(Graphics2DRenderable renderer) throws JRException { int normalWidth = availableImageWidth; int normalHeight = availableImageHeight; Dimension2D dimension = renderer instanceof DimensionRenderable ? ((DimensionRenderable)renderer).getDimension(jasperReportsContext) : null; if (dimension != null) { normalWidth = (int) dimension.getWidth(); normalHeight = (int) dimension.getHeight(); } int dpi = getPropertiesUtil().getIntegerProperty(Renderable.PROPERTY_IMAGE_DPI, 72); double scale = dpi/72d; BufferedImage bi = new BufferedImage( (int)(scale * availableImageWidth), (int)(scale * availableImageHeight), BufferedImage.TYPE_INT_ARGB ); Graphics2D grx = bi.createGraphics(); try { grx.scale(scale, scale); grx.clip( new Rectangle( 0, 0, availableImageWidth, availableImageHeight ) ); renderer.render( jasperReportsContext, grx, new Rectangle( (int) (ImageUtil.getXAlignFactor(imageElement) * (availableImageWidth - normalWidth)), (int) (ImageUtil.getYAlignFactor(imageElement) * (availableImageHeight - normalHeight)), normalWidth, normalHeight ) ); } finally { grx.dispose(); } byte[] imageData = null; int topOffset = 0; int leftOffset = 0; int bottomOffset = 0; int rightOffset = 0; topOffset = topPadding; leftOffset = leftPadding; bottomOffset = bottomPadding; rightOffset = rightPadding; imageData = JRImageLoader.getInstance(jasperReportsContext).loadBytesFromAwtImage(bi, ImageTypeEnum.PNG); return new InternalImageProcessorResult(imageData, topOffset, leftOffset, bottomOffset, rightOffset); }
private InternalImageProcessorResult processImageClip(Graphics2DRenderable renderer) throws JRException { int normalWidth = availableImageWidth; int normalHeight = availableImageHeight; Dimension2D dimension = renderer instanceof DimensionRenderable ? ((DimensionRenderable)renderer).getDimension(jasperReportsContext) : null; if (dimension != null) { normalWidth = (int) dimension.getWidth(); normalHeight = (int) dimension.getHeight(); } int dpi = getPropertiesUtil().getIntegerProperty(Renderable.PROPERTY_IMAGE_DPI, 72); double scale = dpi/72d; BufferedImage bi = new BufferedImage( (int)(scale * availableImageWidth), (int)(scale * availableImageHeight), BufferedImage.TYPE_INT_ARGB ); Graphics2D grx = bi.createGraphics(); try { grx.scale(scale, scale); grx.clip( new Rectangle( 0, 0, availableImageWidth, availableImageHeight ) ); renderer.render( jasperReportsContext, grx, new Rectangle( (int) (ImageUtil.getXAlignFactor(imageElement) * (availableImageWidth - normalWidth)), (int) (ImageUtil.getYAlignFactor(imageElement) * (availableImageHeight - normalHeight)), normalWidth, normalHeight ) ); } finally { grx.dispose(); } byte[] imageData = null; int topOffset = 0; int leftOffset = 0; int bottomOffset = 0; int rightOffset = 0; // topOffset = topPadding; // leftOffset = leftPadding; // bottomOffset = bottomPadding; // rightOffset = rightPadding; imageData = JRImageLoader.getInstance(jasperReportsContext).loadBytesFromAwtImage(bi, ImageTypeEnum.PNG); return new InternalImageProcessorResult(imageData, topOffset, leftOffset, bottomOffset, rightOffset); }
@Override public byte[] getData(JasperReportsContext jasperReportsContext) throws JRException { Dimension2D dimension = getDimension(jasperReportsContext); if (dimension == null) { throw new JRException( EXCEPTION_MESSAGE_KEY_DIMENSION_NULL_NOT_ALLOWED, (Object[])null ); } int dpi = getImageDataDPI(jasperReportsContext); double scale = dpi/72d; BufferedImage bi = new BufferedImage( (int) (scale * dimension.getWidth()), (int) (scale * dimension.getHeight()), BufferedImage.TYPE_INT_ARGB // always produce PNGs with transparency ); Graphics2D g = createGraphics(bi); try { g.scale(scale, scale); Color backcolor = getBackcolor(); if (backcolor != null) { g.setColor(backcolor); g.fillRect(0, 0, (int)dimension.getWidth(), (int)dimension.getHeight()); } render(jasperReportsContext, g, new Rectangle((int)dimension.getWidth(), (int)dimension.getHeight())); } finally { g.dispose(); } return JRImageLoader.getInstance(jasperReportsContext).loadBytesFromAwtImage(bi, ImageTypeEnum.PNG); // always produce PNGs with transparency }
/** * */ private MapDesignConverter() { super(JRImageLoader.SUBREPORT_IMAGE_RESOURCE); }
/** * */ private SortComponentDesignConverter() { super(JRImageLoader.SUBREPORT_IMAGE_RESOURCE); }
/** * */ private IconLabelComponentDesignConverter() { super(JRImageLoader.SUBREPORT_IMAGE_RESOURCE);//FIXMEINPUT }
/** * */ private MapDesignConverter() { super(JRImageLoader.COMPONENT_IMAGE_RESOURCE); }
public GoogleChartsDesignConverter() { super(JRImageLoader.SUBREPORT_IMAGE_RESOURCE); }
private WmsMapDesignConverter() { super(JRImageLoader.SUBREPORT_IMAGE_RESOURCE); }