|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.poi.sl.draw.ImageRenderer
public class ImageRenderer
For now this class renders only images supported by the javax.imageio.ImageIO framework. Subclasses can override this class to support other formats, for example, use Apache Batik to render WMF, PICT can be rendered using Apple QuickTime API for Java:
public class MyImageRendener extends 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());
Field Summary | |
---|---|
protected java.awt.image.BufferedImage |
img
|
Constructor Summary | |
---|---|
ImageRenderer()
|
Method Summary | |
---|---|
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.Dimension |
getDimension()
|
java.awt.image.BufferedImage |
getImage()
|
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)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected java.awt.image.BufferedImage img
Constructor Detail |
---|
public ImageRenderer()
Method Detail |
---|
public void loadImage(java.io.InputStream data, java.lang.String contentType) throws java.io.IOException
data
- the raw image streamcontentType
- the content type
java.io.IOException
public void loadImage(byte[] data, java.lang.String contentType) throws java.io.IOException
data
- the raw image streamcontentType
- the content type
java.io.IOException
public java.awt.image.BufferedImage getImage()
public java.awt.Dimension getDimension()
public void setAlpha(double alpha)
alpha
- the alpha [0..1] to be added to the image (possibly already containing an alpha channel)public boolean drawImage(java.awt.Graphics2D graphics, java.awt.geom.Rectangle2D anchor)
public boolean drawImage(java.awt.Graphics2D graphics, java.awt.geom.Rectangle2D anchor, java.awt.Insets clip)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |