net.sf.jasperreports.engine

## Class JRImageRenderer

- java.lang.Object
- - net.sf.jasperreports.engine.JRAbstractRenderer
  - - net.sf.jasperreports.engine.JRImageRenderer

- All Implemented Interfaces:
    java.io.Serializable, JRRenderable, Renderable
  Direct Known Subclasses:
    JRSimpleImageMapRenderer

      public class JRImageRenderer
      extends JRAbstractRenderer

  Provides functionality for image rendering.

  The content of an image element can come either directly from an image file like a JPG, GIF, PNG, or can be a Scalable Vector Graphics (SVG) file that is rendered using some business logic or a special graphics API like a charting or a barcode library. Either way, JasperReports treats images in a very transparent way because it relies on a special interface called `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).
  Version:
    $Id: JRImageRenderer.java 7043 2014-04-24 12:11:59Z shertage $
  Author:
    Teodor Danciu (teodord@users.sourceforge.net)
  See Also:
    `JRAbstractSvgRenderer`, Serialized Form

- - ### Field Summary

    - ### Fields inherited from interface net.sf.jasperreports.engine.Renderable

      `PROPERTY_IMAGE_DPI`

    - ### Fields inherited from interface net.sf.jasperreports.engine.JRRenderable

      `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`

  - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `protected` | `JRImageRenderer(byte[] imageData)`
    `protected` | `JRImageRenderer(java.lang.String imageLocation)`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `java.awt.geom.Dimension2D` | `getDimension()` Deprecated. Replaced by `getDimension(JasperReportsContext)`.
    `java.awt.geom.Dimension2D` | `getDimension(JasperReportsContext jasperReportsContext)`
    `java.awt.Image` | `getImage()` Deprecated. Replaced by `getImage(JasperReportsContext)`.
    `java.awt.Image` | `getImage(JasperReportsContext jasperReportsContext)`
    `byte[]` | `getImageData()` Deprecated. Replaced by `getImageData(JasperReportsContext)`.
    `byte[]` | `getImageData(JasperReportsContext jasperReportsContext)`
    `java.lang.String` | `getImageLocation()`
    `byte` | `getImageType()` Deprecated. Replaced by `getImageTypeValue()`.
    `ImageTypeEnum` | `getImageTypeValue()`
    `static JRImageRenderer` | `getInstance(byte[] imageData)`
    `static JRRenderable` | `getInstance(java.io.File file, OnErrorTypeEnum onErrorType)` Deprecated. Replaced by `RenderableUtil.getRenderable(File, OnErrorTypeEnum)`.
    `static JRRenderable` | `getInstance(java.awt.Image image, byte imageType, OnErrorTypeEnum onErrorType)` Deprecated. Replaced by `RenderableUtil.getRenderable(Image, ImageTypeEnum, OnErrorTypeEnum)`.
    `static JRRenderable` | `getInstance(java.awt.Image img, OnErrorTypeEnum onErrorType)` Deprecated. Replaced by `RenderableUtil.getRenderable(Image, OnErrorTypeEnum)`.
    `static JRRenderable` | `getInstance(java.io.InputStream is, OnErrorTypeEnum onErrorType)` Deprecated. Replaced by `RenderableUtil.getRenderable(InputStream, OnErrorTypeEnum)`.
    `static JRRenderable` | `getInstance(java.lang.String imageLocation)` Deprecated. Replaced by `RenderableUtil.getRenderable(String)`.
    `static JRRenderable` | `getInstance(java.lang.String imageLocation, OnErrorTypeEnum onErrorType)` Deprecated. Replaced by `RenderableUtil.getRenderable(String, OnErrorTypeEnum)`.
    `static JRRenderable` | `getInstance(java.lang.String imageLocation, OnErrorTypeEnum onErrorType, boolean isLazy)` Deprecated. Replaced by `RenderableUtil.getRenderable(String, OnErrorTypeEnum, boolean)`.
    `static JRRenderable` | `getInstance(java.net.URL url, OnErrorTypeEnum onErrorType)` Deprecated. Replaced by `RenderableUtil.getRenderable(URL, OnErrorTypeEnum)`.
    `static JRImageRenderer` | `getOnErrorRenderer(OnErrorTypeEnum onErrorType, JRException e)`
    `static JRImageRenderer` | `getOnErrorRenderer(OnErrorTypeEnum onErrorType, JRRuntimeException e)`
    `static JRRenderable` | `getOnErrorRendererForDimension(JRRenderable renderer, OnErrorTypeEnum onErrorType)` Deprecated. Replaced by `RenderableUtil.getOnErrorRendererForDimension(Renderable, OnErrorTypeEnum)`.
    `static JRImageRenderer` | `getOnErrorRendererForImage(JasperReportsContext jasperReportsContext, JRImageRenderer renderer, OnErrorTypeEnum onErrorType)`
    `static JRImageRenderer` | `getOnErrorRendererForImage(JRImageRenderer renderer, OnErrorTypeEnum onErrorType)` Deprecated. Replaced by `getOnErrorRendererForImage(JasperReportsContext, JRImageRenderer, OnErrorTypeEnum)`.
    `static JRRenderable` | `getOnErrorRendererForImageData(JRRenderable renderer, OnErrorTypeEnum onErrorType)` Deprecated. Replaced by `RenderableUtil.getOnErrorRendererForImageData(Renderable, OnErrorTypeEnum)`.
    `byte` | `getType()` Deprecated. Replaced by `getTypeValue()`.
    `RenderableTypeEnum` | `getTypeValue()`
    `void` | `render(java.awt.Graphics2D grx, java.awt.geom.Rectangle2D rectangle)` Deprecated. Replaced by `render(JasperReportsContext, Graphics2D, Rectangle2D)`.
    `void` | `render(JasperReportsContext jasperReportsContext, java.awt.Graphics2D grx, java.awt.geom.Rectangle2D rectangle)`

    - ### Methods inherited from class net.sf.jasperreports.engine.JRAbstractRenderer

      `getId`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### JRImageRenderer

          protected JRImageRenderer(byte[] imageData)

    - #### JRImageRenderer

          protected JRImageRenderer(java.lang.String imageLocation)

  - ### Method Detail

    - #### getInstance

          public static JRImageRenderer getInstance(byte[] imageData)

    - #### getInstance

          public static JRRenderable getInstance(java.lang.String imageLocation)
                                          throws JRException

      Deprecated. Replaced by `RenderableUtil.getRenderable(String)`.
      Throws:
        `JRException`

    - #### getInstance

          public static JRRenderable getInstance(java.lang.String imageLocation,
                                 OnErrorTypeEnum onErrorType)
                                          throws JRException

      Deprecated. Replaced by `RenderableUtil.getRenderable(String, OnErrorTypeEnum)`.
      Throws:
        `JRException`

    - #### getInstance

          public static JRRenderable getInstance(java.lang.String imageLocation,
                                 OnErrorTypeEnum onErrorType,
                                 boolean isLazy)
                                          throws JRException

      Deprecated. Replaced by `RenderableUtil.getRenderable(String, OnErrorTypeEnum, boolean)`.
      Throws:
        `JRException`

    - #### getInstance

          public static JRRenderable getInstance(java.awt.Image img,
                                 OnErrorTypeEnum onErrorType)
                                          throws JRException

      Deprecated. Replaced by `RenderableUtil.getRenderable(Image, OnErrorTypeEnum)`.
      Throws:
        `JRException`

    - #### getInstance

          public static JRRenderable getInstance(java.awt.Image image,
                                 byte imageType,
                                 OnErrorTypeEnum onErrorType)
                                          throws JRException

      Deprecated. Replaced by `RenderableUtil.getRenderable(Image, ImageTypeEnum, OnErrorTypeEnum)`.
      Creates and returns an instance of the JRImageRenderer class after encoding the image object using an image encoder that supports the supplied image type.
      Parameters:
        `image` - the java.awt.Image object to wrap into a JRImageRenderer instance
        `imageType` - the type of the image as specified by one of the constants defined in the JRRenderable interface
        `onErrorType` - one of the error type constants defined in the `OnErrorTypeEnum`.
      Returns:
        the image renderer instance
      Throws:
        `JRException`

    - #### getInstance

          public static JRRenderable getInstance(java.io.InputStream is,
                                 OnErrorTypeEnum onErrorType)
                                          throws JRException

      Deprecated. Replaced by `RenderableUtil.getRenderable(InputStream, OnErrorTypeEnum)`.
      Throws:
        `JRException`

    - #### getInstance

          public static JRRenderable getInstance(java.net.URL url,
                                 OnErrorTypeEnum onErrorType)
                                          throws JRException

      Deprecated. Replaced by `RenderableUtil.getRenderable(URL, OnErrorTypeEnum)`.
      Throws:
        `JRException`

    - #### getInstance

          public static JRRenderable getInstance(java.io.File file,
                                 OnErrorTypeEnum onErrorType)
                                          throws JRException

      Deprecated. Replaced by `RenderableUtil.getRenderable(File, OnErrorTypeEnum)`.
      Throws:
        `JRException`

    - #### getOnErrorRendererForDimension

          public static JRRenderable getOnErrorRendererForDimension(JRRenderable renderer,
                                                    OnErrorTypeEnum onErrorType)
                                                             throws JRException

      Deprecated. Replaced by `RenderableUtil.getOnErrorRendererForDimension(Renderable, OnErrorTypeEnum)`.
      Throws:
        `JRException`

    - #### getOnErrorRendererForImageData

          public static JRRenderable getOnErrorRendererForImageData(JRRenderable renderer,
                                                    OnErrorTypeEnum onErrorType)
                                                             throws JRException

      Deprecated. Replaced by `RenderableUtil.getOnErrorRendererForImageData(Renderable, OnErrorTypeEnum)`.
      Throws:
        `JRException`

    - #### getOnErrorRendererForImage

          public static JRImageRenderer getOnErrorRendererForImage(JasperReportsContext jasperReportsContext,
                                                   JRImageRenderer renderer,
                                                   OnErrorTypeEnum onErrorType)
                                                            throws JRException

      Throws:
        `JRException`

    - #### getOnErrorRendererForImage

          public static JRImageRenderer getOnErrorRendererForImage(JRImageRenderer renderer,
                                                   OnErrorTypeEnum onErrorType)
                                                            throws JRException

      Deprecated. Replaced by `getOnErrorRendererForImage(JasperReportsContext, JRImageRenderer, OnErrorTypeEnum)`.
      Throws:
        `JRException`

    - #### getOnErrorRenderer

          public static JRImageRenderer getOnErrorRenderer(OnErrorTypeEnum onErrorType,
                                           JRException e)
                                                    throws JRException

      Throws:
        `JRException`

    - #### getOnErrorRenderer

          public static JRImageRenderer getOnErrorRenderer(OnErrorTypeEnum onErrorType,
                                           JRRuntimeException e)
                                                    throws JRRuntimeException

      Throws:
        `JRRuntimeException`

    - #### getImage

          public java.awt.Image getImage(JasperReportsContext jasperReportsContext)
                                  throws JRException

      Throws:
        `JRException`

    - #### getImage

          public java.awt.Image getImage()
                                  throws JRException

      Deprecated. Replaced by `getImage(JasperReportsContext)`.
      Throws:
        `JRException`

    - #### getImageLocation

          public java.lang.String getImageLocation()

    - #### getType

          public byte getType()

      Deprecated. Replaced by `getTypeValue()`.

    - #### getImageType

          public byte getImageType()

      Deprecated. Replaced by `getImageTypeValue()`.

    - #### getTypeValue

          public RenderableTypeEnum getTypeValue()

      Specified by:
        `getTypeValue` in interface `Renderable`
      Overrides:
        `getTypeValue` in class `JRAbstractRenderer`

    - #### getImageTypeValue

          public ImageTypeEnum getImageTypeValue()

      Specified by:
        `getImageTypeValue` in interface `Renderable`
      Overrides:
        `getImageTypeValue` in class `JRAbstractRenderer`

    - #### getDimension

          public java.awt.geom.Dimension2D getDimension()
                                                 throws JRException

      Deprecated. Replaced by `getDimension(JasperReportsContext)`.
      Throws:
        `JRException`

    - #### getDimension

          public java.awt.geom.Dimension2D getDimension(JasperReportsContext jasperReportsContext)
                                                 throws JRException

      Specified by:
        `getDimension` in interface `Renderable`
      Overrides:
        `getDimension` in class `JRAbstractRenderer`
      Throws:
        `JRException`

    - #### getImageData

          public byte[] getImageData(JasperReportsContext jasperReportsContext)
                              throws JRException

      Specified by:
        `getImageData` in interface `Renderable`
      Overrides:
        `getImageData` in class `JRAbstractRenderer`
      Throws:
        `JRException`

    - #### getImageData

          public byte[] getImageData()
                              throws JRException

      Deprecated. Replaced by `getImageData(JasperReportsContext)`.
      Throws:
        `JRException`

    - #### render

          public void render(java.awt.Graphics2D grx,
                    java.awt.geom.Rectangle2D rectangle)
                      throws JRException

      Deprecated. Replaced by `render(JasperReportsContext, Graphics2D, Rectangle2D)`.
      Throws:
        `JRException`

    - #### render

          public void render(JasperReportsContext jasperReportsContext,
                    java.awt.Graphics2D grx,
                    java.awt.geom.Rectangle2D rectangle)
                      throws JRException

      Specified by:
        `render` in interface `Renderable`
      Overrides:
        `render` in class `JRAbstractRenderer`
      Throws:
        `JRException`

© 2001-2010 Jaspersoft Corporation www.jaspersoft.com