Top Description Methods
org.apache.poi.sl.draw

public Interface ImageRenderer

Known Direct Implementers
org.apache.poi.sl.draw.BitmapImageRenderer
Imports
java.awt.Graphics2D, .Insets, java.awt.geom.Dimension2D, .Rectangle2D, java.awt.image.BufferedImage, java.io.IOException, .InputStream, java.nio.charset.Charset, org.apache.poi.common.usermodel.GenericRecord, org.apache.poi.util.Dimension2DDouble

Classes can implement this interfaces to support other formats, for example, use Apache Batik to render WMF (since POI 4.0, there's an internal WMF/EMF/EMF+ renderer in POI), PICT can be rendered using Apple QuickTime API for Java:

public class MyImageRendener implements ImageRendener {
    InputStream data;

    public boolean drawImage(Graphics2D graphics,Rectangle2D anchor,Insets clip) {
        // draw image
      DataInputStream is = new DataInputStream(data);
      org.apache.batik.transcoder.wmf.tosvg.WMFRecordStore wmfStore =
              new org.apache.batik.transcoder.wmf.tosvg.WMFRecordStore();
      try {
          wmfStore.read(is);
      } catch (IOException e){
          return;
      }

      float scale = (float)anchor.width/wmfStore.getWidthPixels();

      org.apache.batik.transcoder.wmf.tosvg.WMFPainter painter =
              new org.apache.batik.transcoder.wmf.tosvg.WMFPainter(wmfStore, 0, 0, scale);
      graphics.translate(anchor.x, anchor.y);
      painter.paint(graphics);
    }

    public void loadImage(InputStream data, String contentType) throws IOException {
        if ("image/wmf".equals(contentType)) {
            this.data = data;
            // use Apache Batik to handle WMF
        } else {
            super.loadImage(data,contentType);
        }
    }
}

and then pass this class to your instance of java.awt.Graphics2D:

graphics.setRenderingHint(Drawable.IMAGE_RENDERER, new MyImageRendener());

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

if the content type is supported
canRender
(String
the image content type
contentType
)

Determines if this image renderer implementation supports the given contentType

public boolean

Returns:

true if the picture data was successfully rendered
drawImage
(Graphics2D graphics, Rectangle2D anchor)

Render picture data into the supplied graphics

public boolean

Returns:

true if the picture data was successfully rendered
drawImage
(Graphics2D graphics, Rectangle2D anchor, Insets clip)

Render picture data into the supplied graphics

public Rectangle2D

Returns:

the bounds of the buffered image in pixel
getBounds
()

public default String

Returns:

the cached content type
getCachedContentType
()

public default byte[]

Returns:

the cached image data
getCachedImage
()

public default Dimension2D

Returns:

the dimension of the buffered image in pixel
getDimension
()

public default GenericRecord
public BufferedImage

Returns:

the image as buffered image or null if image could not be loaded
getImage
()

public BufferedImage

Returns:

the image as buffered image or null if image could not be loaded
getImage
(Dimension2D
the dimension in pixels of the returned image
dim
)

public Rectangle2D

Returns:

the format-specific / not-normalized bounds of the image
getNativeBounds
()

public void
loadImage(InputStream
the raw image stream
data
,
String
the content type
contentType
)

Load and buffer the image

public void
loadImage(byte[]
the raw image bytes
data
,
String
the content type
contentType
)

Load and buffer the image

public void
setAlpha(double
the alpha [0..1] to be added to the image (possibly already containing an alpha channel)
alpha
)

public default void
setCacheInput(boolean
dis-/enables caching - this is an optional operation. false removes already cached data
enable
)

Dis-/Enables caching of input data for later retrieval.

public default void
setDefaultCharset(Charset
the default charset
defaultCharset
)

Sets the default charset to render text elements.

Method Detail

canRenderback to summary
public boolean canRender(String contentType)

Determines if this image renderer implementation supports the given contentType

Parameters
contentType:String

the image content type

Returns:boolean

if the content type is supported

drawImageback to summary
public boolean drawImage(Graphics2D graphics, Rectangle2D anchor)

Render picture data into the supplied graphics

Returns:boolean

true if the picture data was successfully rendered

drawImageback to summary
public boolean drawImage(Graphics2D graphics, Rectangle2D anchor, Insets clip)

Render picture data into the supplied graphics

Returns:boolean

true if the picture data was successfully rendered

getBoundsback to summary
public Rectangle2D getBounds()
Returns:Rectangle2D

the bounds of the buffered image in pixel

getCachedContentTypeback to summary
public default String getCachedContentType()
Returns:String

the cached content type

getCachedImageback to summary
public default byte[] getCachedImage()
Returns:byte[]

the cached image data

getDimensionback to summary
public default Dimension2D getDimension()
Returns:Dimension2D

the dimension of the buffered image in pixel

getGenericRecordback to summary
public default GenericRecord getGenericRecord()
getImageback to summary
public BufferedImage getImage()
Returns:BufferedImage

the image as buffered image or null if image could not be loaded

getImageback to summary
public BufferedImage getImage(Dimension2D dim)
Parameters
dim:Dimension2D

the dimension in pixels of the returned image

Returns:BufferedImage

the image as buffered image or null if image could not be loaded

Since
POI 3.15-beta2
getNativeBoundsback to summary
public Rectangle2D getNativeBounds()
Returns:Rectangle2D

the format-specific / not-normalized bounds of the image

loadImageback to summary
public void loadImage(InputStream data, String contentType) throws IOException

Load and buffer the image

Parameters
data:InputStream

the raw image stream

contentType:String

the content type

loadImageback to summary
public void loadImage(byte[] data, String contentType) throws IOException

Load and buffer the image

Parameters
data:byte[]

the raw image bytes

contentType:String

the content type

setAlphaback to summary
public void setAlpha(double alpha)
Parameters
alpha:double

the alpha [0..1] to be added to the image (possibly already containing an alpha channel)

setCacheInputback to summary
public default void setCacheInput(boolean enable)

Dis-/Enables caching of input data for later retrieval. Opposed to getImage(), which returns a BufferedImage, the cached image can be later used to embedded the original, unmodified data

Parameters
enable:boolean

dis-/enables caching - this is an optional operation. false removes already cached data

setDefaultCharsetback to summary
public default void setDefaultCharset(Charset defaultCharset)

Sets the default charset to render text elements. Opposed to other windows libraries in POI this simply defaults to Windows-1252.

Parameters
defaultCharset:Charset

the default charset