public class JRImageRenderer extends JRAbstractRenderer
Renderable
to offer a common
way to render images.
The Renderable
interface has a method called
render(JasperReportsContext, Graphics2D, Rectangle2D)
,
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_DPI
IMAGE_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) |
getId
protected JRImageRenderer(byte[] imageData)
protected JRImageRenderer(String imageLocation)
public static JRImageRenderer getInstance(byte[] imageData)
public static JRRenderable getInstance(String imageLocation) throws JRException
RenderableUtil.getRenderable(String)
.JRException
public static JRRenderable getInstance(String imageLocation, OnErrorTypeEnum onErrorType) throws JRException
RenderableUtil.getRenderable(String, OnErrorTypeEnum)
.JRException
public static JRRenderable getInstance(String imageLocation, OnErrorTypeEnum onErrorType, boolean isLazy) throws JRException
RenderableUtil.getRenderable(String, OnErrorTypeEnum, boolean)
.JRException
public static JRRenderable getInstance(Image img, OnErrorTypeEnum onErrorType) throws JRException
RenderableUtil.getRenderable(Image, OnErrorTypeEnum)
.JRException
public 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
.JRException
public static JRRenderable getInstance(InputStream is, OnErrorTypeEnum onErrorType) throws JRException
RenderableUtil.getRenderable(InputStream, OnErrorTypeEnum)
.JRException
public static JRRenderable getInstance(URL url, OnErrorTypeEnum onErrorType) throws JRException
RenderableUtil.getRenderable(URL, OnErrorTypeEnum)
.JRException
public static JRRenderable getInstance(File file, OnErrorTypeEnum onErrorType) throws JRException
RenderableUtil.getRenderable(File, OnErrorTypeEnum)
.JRException
public static JRRenderable getOnErrorRendererForDimension(JRRenderable renderer, OnErrorTypeEnum onErrorType) throws JRException
RenderableUtil.getOnErrorRendererForDimension(Renderable, OnErrorTypeEnum)
.JRException
public static JRRenderable getOnErrorRendererForImageData(JRRenderable renderer, OnErrorTypeEnum onErrorType) throws JRException
RenderableUtil.getOnErrorRendererForImageData(Renderable, OnErrorTypeEnum)
.JRException
public static JRImageRenderer getOnErrorRendererForImage(JasperReportsContext jasperReportsContext, JRImageRenderer renderer, OnErrorTypeEnum onErrorType) throws JRException
JRException
public static JRImageRenderer getOnErrorRendererForImage(JRImageRenderer renderer, OnErrorTypeEnum onErrorType) throws JRException
getOnErrorRendererForImage(JasperReportsContext, JRImageRenderer, OnErrorTypeEnum)
.JRException
public static JRImageRenderer getOnErrorRenderer(OnErrorTypeEnum onErrorType, JRException e) throws JRException
JRException
public static JRImageRenderer getOnErrorRenderer(OnErrorTypeEnum onErrorType, JRRuntimeException e) throws JRRuntimeException
JRRuntimeException
public Image getImage(JasperReportsContext jasperReportsContext) throws JRException
JRException
public Image getImage() throws JRException
getImage(JasperReportsContext)
.JRException
public String getImageLocation()
public byte getType()
getTypeValue()
.public byte getImageType()
getImageTypeValue()
.public RenderableTypeEnum getTypeValue()
getTypeValue
in interface Renderable
getTypeValue
in class JRAbstractRenderer
public ImageTypeEnum getImageTypeValue()
getImageTypeValue
in interface Renderable
getImageTypeValue
in class JRAbstractRenderer
public Dimension2D getDimension() throws JRException
getDimension(JasperReportsContext)
.JRException
public Dimension2D getDimension(JasperReportsContext jasperReportsContext) throws JRException
getDimension
in interface Renderable
getDimension
in class JRAbstractRenderer
JRException
public byte[] getImageData(JasperReportsContext jasperReportsContext) throws JRException
getImageData
in interface Renderable
getImageData
in class JRAbstractRenderer
JRException
public byte[] getImageData() throws JRException
getImageData(JasperReportsContext)
.JRException
public void render(Graphics2D grx, Rectangle2D rectangle) throws JRException
render(JasperReportsContext, Graphics2D, Rectangle2D)
.JRException
public void render(JasperReportsContext jasperReportsContext, Graphics2D grx, Rectangle2D rectangle) throws JRException
render
in interface Renderable
render
in class JRAbstractRenderer
JRException
Copyright © 2015. All rights reserved.