Top Description Inners Fields Constructors Methods
org.apache.poi.sl.draw

public Class BitmapImageRenderer

extends Object
implements ImageRenderer
Class Inheritance
All Implemented Interfaces
org.apache.poi.sl.draw.ImageRenderer
Imports
java.awt.Graphics, .Graphics2D, .Insets, .Shape, java.awt.geom.AffineTransform, .Dimension2D, .Rectangle2D, java.awt.image.AffineTransformOp, .BufferedImage, .RescaleOp, java.io.IOException, .InputStream, java.util.Iterator, java.util.stream.Stream, .StreamSupport, javax.imageio.ImageIO, .ImageReadParam, .ImageReader, .ImageTypeSpecifier, javax.imageio.stream.ImageInputStream, .MemoryCacheImageInputStream, org.apache.commons.collections4.iterators.IteratorIterable, org.apache.commons.io.input.UnsynchronizedByteArrayInputStream, org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream, org.apache.logging.log4j.LogManager, .Logger, org.apache.poi.sl.usermodel.PictureData.PictureType, org.apache.poi.util.IOUtils

For now this class renders only images supported by the javax.imageio.ImageIO framework.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static interface

Field Summary

Modifier and TypeField and Description
private static final PictureData.PictureType[]
private String
private byte[]
private boolean
private static final BitmapImageRenderer.ImageLoader[]
protected BufferedImage
private static final Logger
private static final String

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public boolean
canRender(String
the image content type
contentType
)

Implements org.apache.poi.sl.draw.ImageRenderer.canRender.

Determines if this image renderer implementation supports the given contentType

public boolean
drawImage(Graphics2D graphics, Rectangle2D anchor)

Implements org.apache.poi.sl.draw.ImageRenderer.drawImage.

Render picture data into the supplied graphics

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

Implements org.apache.poi.sl.draw.ImageRenderer.drawImage.

Render picture data into the supplied graphics

private static int
findTruncatedBlackBox(BufferedImage img, int width, int height)

public Rectangle2D
public String
public byte[]
public BufferedImage
public BufferedImage
getImage(Dimension2D
the dimension in pixels of the returned image
dim
)

Implements org.apache.poi.sl.draw.ImageRenderer.getImage.

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

Implements org.apache.poi.sl.draw.ImageRenderer.loadImage.

Load and buffer the image

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

Implements org.apache.poi.sl.draw.ImageRenderer.loadImage.

Load and buffer the image

private static BufferedImage
private static BufferedImage

Returns:

the bufferedImage or null, if there was no image reader for this content type
readImage
(final InputStream
the data stream
data
,
final String
the content type
contentType
)

Read the image data via ImageIO and optionally try to workaround metadata errors.

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

Implements org.apache.poi.sl.draw.ImageRenderer.setAlpha.

public static BufferedImage
setAlpha(BufferedImage image, double alpha)

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

Overrides default org.apache.poi.sl.draw.ImageRenderer.setCacheInput.

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

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

ALLOWED_TYPESback to summary
private static final PictureData.PictureType[] ALLOWED_TYPES
cachedContentTypeback to summary
private String cachedContentType
cachedImageback to summary
private byte[] cachedImage
doCacheback to summary
private boolean doCache
IMAGE_LOADERSback to summary
private static final BitmapImageRenderer.ImageLoader[] IMAGE_LOADERS
imgback to summary
protected BufferedImage img
LOGback to summary
private static final Logger LOG
UNSUPPORTED_IMAGE_TYPEback to summary
private static final String UNSUPPORTED_IMAGE_TYPE

Constructor Detail

BitmapImageRendererback to summary
public BitmapImageRenderer()

Method Detail

canRenderback to summary
public boolean canRender(String contentType)

Implements org.apache.poi.sl.draw.ImageRenderer.canRender.

Doc from org.apache.poi.sl.draw.ImageRenderer.canRender.

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

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

Implements org.apache.poi.sl.draw.ImageRenderer.drawImage.

Doc from org.apache.poi.sl.draw.ImageRenderer.drawImage.

Render picture data into the supplied graphics

Returns:boolean

true if the picture data was successfully rendered

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

Implements org.apache.poi.sl.draw.ImageRenderer.drawImage.

Doc from org.apache.poi.sl.draw.ImageRenderer.drawImage.

Render picture data into the supplied graphics

Returns:boolean

true if the picture data was successfully rendered

Annotations
@Override
findTruncatedBlackBoxback to summary
private static int findTruncatedBlackBox(BufferedImage img, int width, int height)
getBoundsback to summary
public Rectangle2D getBounds()

Implements org.apache.poi.sl.draw.ImageRenderer.getBounds.

Returns:Rectangle2D

Doc from org.apache.poi.sl.draw.ImageRenderer.getBounds.

the bounds of the buffered image in pixel

Annotations
@Override
getCachedContentTypeback to summary
public String getCachedContentType()

Overrides default org.apache.poi.sl.draw.ImageRenderer.getCachedContentType.

Returns:String

Doc from org.apache.poi.sl.draw.ImageRenderer.getCachedContentType.

the cached content type

Annotations
@Override
getCachedImageback to summary
public byte[] getCachedImage()

Overrides default org.apache.poi.sl.draw.ImageRenderer.getCachedImage.

Returns:byte[]

Doc from org.apache.poi.sl.draw.ImageRenderer.getCachedImage.

the cached image data

Annotations
@Override
getImageback to summary
public BufferedImage getImage()

Implements org.apache.poi.sl.draw.ImageRenderer.getImage.

Returns:BufferedImage

Doc from org.apache.poi.sl.draw.ImageRenderer.getImage.

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

Annotations
@Override
getImageback to summary
public BufferedImage getImage(Dimension2D dim)

Implements org.apache.poi.sl.draw.ImageRenderer.getImage.

Parameters
dim:Dimension2D

Doc from org.apache.poi.sl.draw.ImageRenderer.getImage.

the dimension in pixels of the returned image

Returns:BufferedImage

Doc from org.apache.poi.sl.draw.ImageRenderer.getImage.

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

Annotations
@Override
getNativeBoundsback to summary
public Rectangle2D getNativeBounds()

Implements org.apache.poi.sl.draw.ImageRenderer.getNativeBounds.

Returns:Rectangle2D

Doc from org.apache.poi.sl.draw.ImageRenderer.getNativeBounds.

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

Annotations
@Override
loadColoredback to summary
private static BufferedImage loadColored(ImageReader reader, ImageInputStream iis, ImageReadParam param) throws IOException
loadGrayScaledback to summary
private static BufferedImage loadGrayScaled(ImageReader reader, ImageInputStream iis, ImageReadParam param) throws IOException
loadImageback to summary
public void loadImage(InputStream data, String contentType) throws IOException

Implements org.apache.poi.sl.draw.ImageRenderer.loadImage.

Doc from org.apache.poi.sl.draw.ImageRenderer.loadImage.

Load and buffer the image

Parameters
data:InputStream

the raw image stream

contentType:String

the content type

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

Implements org.apache.poi.sl.draw.ImageRenderer.loadImage.

Doc from org.apache.poi.sl.draw.ImageRenderer.loadImage.

Load and buffer the image

Parameters
data:byte[]

the raw image bytes

contentType:String

the content type

Annotations
@Override
loadTruncatedback to summary
private static BufferedImage loadTruncated(ImageReader reader, ImageInputStream iis, ImageReadParam param) throws IOException
readImageback to summary
private static BufferedImage readImage(final InputStream data, final String contentType) throws IOException

Read the image data via ImageIO and optionally try to workaround metadata errors. The resulting image is of image type BufferedImage#TYPE_INT_ARGB

Parameters
data:InputStream

the data stream

contentType:String

the content type

Returns:BufferedImage

the bufferedImage or null, if there was no image reader for this content type

Exceptions
IOException:
thrown if there was an error while processing the image
setAlphaback to summary
public void setAlpha(double alpha)

Implements org.apache.poi.sl.draw.ImageRenderer.setAlpha.

Parameters
alpha:double

Doc from org.apache.poi.sl.draw.ImageRenderer.setAlpha.

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

Annotations
@Override
setAlphaback to summary
public static BufferedImage setAlpha(BufferedImage image, double alpha)
setCacheInputback to summary
public void setCacheInput(boolean enable)

Overrides default org.apache.poi.sl.draw.ImageRenderer.setCacheInput.

Doc from org.apache.poi.sl.draw.ImageRenderer.setCacheInput.

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

Annotations
@Override
org.apache.poi.sl.draw back to summary

private Interface BitmapImageRenderer.ImageLoader


Method Summary

Modifier and TypeMethod and Description
public BufferedImage

Method Detail

loadback to summary
public BufferedImage load(ImageReader reader, ImageInputStream iis, ImageReadParam param) throws IOException