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 |
|---|---|
| public boolean | |
| public boolean | Returns: true if the picture data was successfully renderedRender picture data into the supplied graphics |
| public boolean | Returns: true if the picture data was successfully renderedRender picture data into the supplied graphics |
| public Rectangle2D | |
| public default String | |
| public default byte[] | |
| public default Dimension2D | |
| public default GenericRecord | |
| public BufferedImage | |
| public BufferedImage | Returns: the image as buffered image or null if image could not be loadedthe dimension in pixels of the returned image dim)
|
| public Rectangle2D | |
| public void | loadImage(InputStream
the raw image stream data, String the content type contentType)Load and buffer the image |
| public void | |
| 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. enable)false removes already cached dataDis-/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. |
| canRender | back to summary |
|---|---|
| public boolean canRender(String contentType) Determines if this image renderer implementation supports the given contentType
| |
| drawImage | back to summary |
|---|---|
| public boolean drawImage(Graphics2D graphics, Rectangle2D anchor) Render picture data into the supplied graphics
| |
| drawImage | back to summary |
|---|---|
| public boolean drawImage(Graphics2D graphics, Rectangle2D anchor, Insets clip) Render picture data into the supplied graphics
| |
| getBounds | back to summary |
|---|---|
public Rectangle2D getBounds()
| |
| getCachedContentType | back to summary |
|---|---|
public default String getCachedContentType()
| |
| getCachedImage | back to summary |
|---|---|
public default byte[] getCachedImage()
| |
| getDimension | back to summary |
|---|---|
public default Dimension2D getDimension()
| |
| getGenericRecord | back to summary |
|---|---|
| public default GenericRecord getGenericRecord() | |
| getImage | back to summary |
|---|---|
public BufferedImage getImage()
| |
| getImage | back to summary |
|---|---|
public BufferedImage getImage(Dimension2D dim)
| |
| getNativeBounds | back to summary |
|---|---|
public Rectangle2D getNativeBounds()
| |
| loadImage | back to summary |
|---|---|
| public void loadImage(InputStream data, String contentType) throws IOException Load and buffer the image
| |
| loadImage | back to summary |
|---|---|
| public void loadImage(byte[] data, String contentType) throws IOException Load and buffer the image
| |
| setAlpha | back to summary |
|---|---|
public void setAlpha(double alpha)
| |
| setCacheInput | back to summary |
|---|---|
| public default void setCacheInput(boolean enable) Dis-/Enables caching of input data for later retrieval.
Opposed to
| |
| setDefaultCharset | back 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.
| |