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 |
drawImage(Graphics2D graphics,
Rectangle2D anchor)
Render picture data into the supplied graphics
|
boolean |
drawImage(Graphics2D graphics,
Rectangle2D anchor,
Insets clip)
Render picture data into the supplied graphics
|
Dimension |
getDimension() |
BufferedImage |
getImage() |
BufferedImage |
getImage(Dimension dim) |
void |
loadImage(byte[] data,
String contentType)
Load and buffer the image
|
void |
loadImage(InputStream data,
String contentType)
Load and buffer the image
|
void |
setAlpha(double alpha) |
void loadImage(InputStream data, String contentType) throws IOException
data
- the raw image streamcontentType
- the content typeIOException
void loadImage(byte[] data, String contentType) throws IOException
data
- the raw image bytescontentType
- the content typeIOException
Dimension getDimension()
void setAlpha(double alpha)
alpha
- the alpha [0..1] to be added to the image (possibly already containing an alpha channel)BufferedImage getImage()
BufferedImage getImage(Dimension dim)
dim
- the dimension in pixels of the returned imageboolean drawImage(Graphics2D graphics, Rectangle2D anchor)
boolean drawImage(Graphics2D graphics, Rectangle2D anchor, Insets clip)
Copyright © 2010 - 2020 Adobe. All Rights Reserved