public interface ImageRenderer
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());
Modifier and Type | Method and Description |
---|---|
boolean |
canRender(java.lang.String contentType)
Determines if this image renderer implementation supports the given contentType
|
boolean |
drawImage(java.awt.Graphics2D graphics,
java.awt.geom.Rectangle2D anchor)
Render picture data into the supplied graphics
|
boolean |
drawImage(java.awt.Graphics2D graphics,
java.awt.geom.Rectangle2D anchor,
java.awt.Insets clip)
Render picture data into the supplied graphics
|
java.awt.geom.Rectangle2D |
getBounds() |
default java.awt.geom.Dimension2D |
getDimension() |
default GenericRecord |
getGenericRecord() |
java.awt.image.BufferedImage |
getImage() |
java.awt.image.BufferedImage |
getImage(java.awt.geom.Dimension2D dim) |
java.awt.geom.Rectangle2D |
getNativeBounds() |
void |
loadImage(byte[] data,
java.lang.String contentType)
Load and buffer the image
|
void |
loadImage(java.io.InputStream data,
java.lang.String contentType)
Load and buffer the image
|
void |
setAlpha(double alpha) |
default void |
setDefaultCharset(java.nio.charset.Charset defaultCharset)
Sets the default charset to render text elements.
|
boolean canRender(java.lang.String contentType)
contentType
- the image content typevoid loadImage(java.io.InputStream data, java.lang.String contentType) throws java.io.IOException
data
- the raw image streamcontentType
- the content typejava.io.IOException
void loadImage(byte[] data, java.lang.String contentType) throws java.io.IOException
data
- the raw image bytescontentType
- the content typejava.io.IOException
java.awt.geom.Rectangle2D getNativeBounds()
java.awt.geom.Rectangle2D getBounds()
default java.awt.geom.Dimension2D getDimension()
void setAlpha(double alpha)
alpha
- the alpha [0..1] to be added to the image (possibly already containing an alpha channel)java.awt.image.BufferedImage getImage()
java.awt.image.BufferedImage getImage(java.awt.geom.Dimension2D dim)
dim
- the dimension in pixels of the returned imageboolean drawImage(java.awt.Graphics2D graphics, java.awt.geom.Rectangle2D anchor)
boolean drawImage(java.awt.Graphics2D graphics, java.awt.geom.Rectangle2D anchor, java.awt.Insets clip)
default GenericRecord getGenericRecord()
default void setDefaultCharset(java.nio.charset.Charset defaultCharset)
defaultCharset
- the default charsetCopyright 2021 The Apache Software Foundation or its licensors, as applicable.