public class JRImageRenderer extends JRAbstractRenderer
Renderable to offer a common
way to render images.
The Renderable interface has a method called
render(JasperReportsContext jasperReportsContext, Graphics2D grx, Rectangle2D rectangle),
which gets called by the engine each time it needs to draw the image
on a given device or graphic context. This approach provides the best quality for the
SVG images when they must be drawn on unknown devices or zoomed into without
losing sharpness.
Other methods specified in this interface can be used to obtain the native size of the
actual image that the renderer wraps or the binary data for an image that must be stored
in a separate file during export.
The library comes with a default implementation for the
Renderable interface that
wraps images that come from files or binary image data in JPG, GIF, or PNG format.
This is the JRImageRenderer class, which is actually a container
for the binary image data, used to load a java.awt.Image object from it.
Then it draws the loaded image on the supplied java.awt.Graphics2D context when the engine
requires it.
Image renderers are serializable because inside the generated document for each image is
a renderer object kept as reference, which is serialized along with the whole
JasperPrint object.
When a JRImageRenderer instance is serialized,
so is the binary image data it contains.
However, if the image element must be lazy loaded (see the isLazy image attribute), then the
engine will not load the binary image data at report-filling time. Rather, it stores inside
the renderer only the java.lang.String location of the image. The actual image data
is loaded only when needed for rendering at report-export or view time.
To simplify the implementation of SVG image renderers, JasperReports ships with an
abstract rendered JRAbstractSvgRenderer. This
implementation contains the code to produce binary image data from the SVG graphic in
JPG format. This is needed when the image must be stored in separate files on disk or
delivered in binary format to a consumer (like a web browser).JRAbstractSvgRenderer,
Serialized FormPROPERTY_IMAGE_DPIIMAGE_TYPE_GIF, IMAGE_TYPE_JPEG, IMAGE_TYPE_PNG, IMAGE_TYPE_TIFF, IMAGE_TYPE_UNKNOWN, MIME_TYPE_GIF, MIME_TYPE_JPEG, MIME_TYPE_PNG, MIME_TYPE_TIFF, TYPE_IMAGE, TYPE_SVG| Modifier | Constructor and Description |
|---|---|
protected |
JRImageRenderer(byte[] imageData) |
protected |
JRImageRenderer(String imageLocation) |
getIdprotected JRImageRenderer(byte[] imageData)
protected JRImageRenderer(String imageLocation)
public static JRImageRenderer getInstance(byte[] imageData)
public static JRRenderable getInstance(String imageLocation) throws JRException
RenderableUtil.getRenderable(String).JRExceptionpublic static JRRenderable getInstance(String imageLocation, OnErrorTypeEnum onErrorType) throws JRException
RenderableUtil.getRenderable(String, OnErrorTypeEnum).JRExceptionpublic static JRRenderable getInstance(String imageLocation, OnErrorTypeEnum onErrorType, boolean isLazy) throws JRException
RenderableUtil.getRenderable(String, OnErrorTypeEnum, boolean).JRExceptionpublic static JRRenderable getInstance(Image img, OnErrorTypeEnum onErrorType) throws JRException
RenderableUtil.getRenderable(Image, OnErrorTypeEnum).JRExceptionpublic static JRRenderable getInstance(Image image, byte imageType, OnErrorTypeEnum onErrorType) throws JRException
RenderableUtil.getRenderable(Image, ImageTypeEnum, OnErrorTypeEnum).image - the java.awt.Image object to wrap into a JRImageRenderer instanceimageType - the type of the image as specified by one of the constants defined in the JRRenderable interfaceonErrorType - one of the error type constants defined in the OnErrorTypeEnum.JRExceptionpublic static JRRenderable getInstance(InputStream is, OnErrorTypeEnum onErrorType) throws JRException
RenderableUtil.getRenderable(InputStream, OnErrorTypeEnum).JRExceptionpublic static JRRenderable getInstance(URL url, OnErrorTypeEnum onErrorType) throws JRException
RenderableUtil.getRenderable(URL, OnErrorTypeEnum).JRExceptionpublic static JRRenderable getInstance(File file, OnErrorTypeEnum onErrorType) throws JRException
RenderableUtil.getRenderable(File, OnErrorTypeEnum).JRExceptionpublic static JRRenderable getOnErrorRendererForDimension(JRRenderable renderer, OnErrorTypeEnum onErrorType) throws JRException
RenderableUtil.getOnErrorRendererForDimension(Renderable, OnErrorTypeEnum).JRExceptionpublic static JRRenderable getOnErrorRendererForImageData(JRRenderable renderer, OnErrorTypeEnum onErrorType) throws JRException
RenderableUtil.getOnErrorRendererForImageData(Renderable, OnErrorTypeEnum).JRExceptionpublic static JRImageRenderer getOnErrorRendererForImage(JasperReportsContext jasperReportsContext, JRImageRenderer renderer, OnErrorTypeEnum onErrorType) throws JRException
JRExceptionpublic static JRImageRenderer getOnErrorRendererForImage(JRImageRenderer renderer, OnErrorTypeEnum onErrorType) throws JRException
getOnErrorRendererForImage(JasperReportsContext, JRImageRenderer, OnErrorTypeEnum).JRExceptionpublic static JRImageRenderer getOnErrorRenderer(OnErrorTypeEnum onErrorType, JRException e) throws JRException
JRExceptionpublic static JRImageRenderer getOnErrorRenderer(OnErrorTypeEnum onErrorType, JRRuntimeException e) throws JRRuntimeException
JRRuntimeExceptionpublic Image getImage(JasperReportsContext jasperReportsContext) throws JRException
JRExceptionpublic Image getImage() throws JRException
getImage(JasperReportsContext).JRExceptionpublic String getImageLocation()
public byte getType()
getTypeValue().public byte getImageType()
getImageTypeValue().public RenderableTypeEnum getTypeValue()
getTypeValue in interface RenderablegetTypeValue in class JRAbstractRendererpublic ImageTypeEnum getImageTypeValue()
getImageTypeValue in interface RenderablegetImageTypeValue in class JRAbstractRendererpublic Dimension2D getDimension() throws JRException
getDimension(JasperReportsContext).JRExceptionpublic Dimension2D getDimension(JasperReportsContext jasperReportsContext) throws JRException
getDimension in interface RenderablegetDimension in class JRAbstractRendererJRExceptionpublic byte[] getImageData(JasperReportsContext jasperReportsContext) throws JRException
getImageData in interface RenderablegetImageData in class JRAbstractRendererJRExceptionpublic byte[] getImageData()
throws JRException
getImageData(JasperReportsContext).JRExceptionpublic void render(Graphics2D grx, Rectangle2D rectangle) throws JRException
render(JasperReportsContext, Graphics2D, Rectangle2D).JRExceptionpublic void render(JasperReportsContext jasperReportsContext, Graphics2D grx, Rectangle2D rectangle) throws JRException
render in interface Renderablerender in class JRAbstractRendererJRExceptionCopyright © 2014. All rights reserved.