Package org.apache.poi.sl.draw
Interface ImageRenderer
-
- All Known Implementing Classes:
BitmapImageRenderer
public interface ImageRendererClasses 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:
and then pass this class to your instance of java.awt.Graphics2D: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); } } }graphics.setRenderingHint(Drawable.IMAGE_RENDERER, new MyImageRendener());
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description booleancanRender(String contentType)Determines if this image renderer implementation supports the given contentTypebooleandrawImage(Graphics2D graphics, Rectangle2D anchor)Render picture data into the supplied graphicsbooleandrawImage(Graphics2D graphics, Rectangle2D anchor, Insets clip)Render picture data into the supplied graphicsRectangle2DgetBounds()default StringgetCachedContentType()default byte[]getCachedImage()default Dimension2DgetDimension()default GenericRecordgetGenericRecord()BufferedImagegetImage()BufferedImagegetImage(Dimension2D dim)Rectangle2DgetNativeBounds()voidloadImage(byte[] data, String contentType)Load and buffer the imagevoidloadImage(InputStream data, String contentType)Load and buffer the imagevoidsetAlpha(double alpha)default voidsetCacheInput(boolean enable)Dis-/Enables caching of input data for later retrieval.default voidsetDefaultCharset(Charset defaultCharset)Sets the default charset to render text elements.
-
-
-
Method Detail
-
canRender
boolean canRender(String contentType)
Determines if this image renderer implementation supports the given contentType- Parameters:
contentType- the image content type- Returns:
- if the content type is supported
-
loadImage
void loadImage(InputStream data, String contentType) throws IOException
Load and buffer the image- Parameters:
data- the raw image streamcontentType- the content type- Throws:
IOException
-
loadImage
void loadImage(byte[] data, String contentType) throws IOExceptionLoad and buffer the image- Parameters:
data- the raw image bytescontentType- the content type- Throws:
IOException
-
getNativeBounds
Rectangle2D getNativeBounds()
- Returns:
- the format-specific / not-normalized bounds of the image
-
getBounds
Rectangle2D getBounds()
- Returns:
- the bounds of the buffered image in pixel
-
getDimension
default Dimension2D getDimension()
- Returns:
- the dimension of the buffered image in pixel
-
setAlpha
void setAlpha(double alpha)
- Parameters:
alpha- the alpha [0..1] to be added to the image (possibly already containing an alpha channel)
-
getImage
BufferedImage getImage()
- Returns:
- the image as buffered image or null if image could not be loaded
-
getImage
BufferedImage getImage(Dimension2D dim)
- Parameters:
dim- the dimension in pixels of the returned image- Returns:
- the image as buffered image or null if image could not be loaded
- Since:
- POI 3.15-beta2
-
drawImage
boolean drawImage(Graphics2D graphics, Rectangle2D anchor)
Render picture data into the supplied graphics- Returns:
- true if the picture data was successfully rendered
-
drawImage
boolean drawImage(Graphics2D graphics, Rectangle2D anchor, Insets clip)
Render picture data into the supplied graphics- Returns:
- true if the picture data was successfully rendered
-
getGenericRecord
default GenericRecord getGenericRecord()
-
setDefaultCharset
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- the default charset
-
setCacheInput
default void setCacheInput(boolean enable)
Dis-/Enables caching of input data for later retrieval. Opposed togetImage(), which returns aBufferedImage, the cached image can be later used to embedded the original, unmodified data- Parameters:
enable- dis-/enables caching - this is an optional operation.falseremoves already cached data
-
getCachedImage
default byte[] getCachedImage()
- Returns:
- the cached image data
-
getCachedContentType
default String getCachedContentType()
- Returns:
- the cached content type
-
-