Interface ImageRenderer

All Known Implementing Classes:
BitmapImageRenderer, HwmfSLImageRenderer

public interface ImageRenderer
Classes can implement this interfaces 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 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());
 
 
  • Method Details

    • loadImage

      void loadImage(InputStream data, String contentType) throws IOException
      Load and buffer the image
      Parameters:
      data - the raw image stream
      contentType - the content type
      Throws:
      IOException
    • loadImage

      void loadImage(byte[] data, String contentType) throws IOException
      Load and buffer the image
      Parameters:
      data - the raw image bytes
      contentType - the content type
      Throws:
      IOException
    • getDimension

      Dimension getDimension()
      Returns:
      the dimension of the buffered image
    • setAlpha

      void setAlpha(double alpha)
      Parameters:
      alpha - the alpha [0..1] to be added to the image (possibly already containing an alpha channel)
    • getImage

      BufferedImage getImage()
      Returns:
      the image as buffered image
    • getImage

      BufferedImage getImage(Dimension dim)
      Parameters:
      dim - the dimension in pixels of the returned image
      Returns:
      the image as buffered image
      Since:
      POI 3.15-beta2
    • drawImage

      boolean drawImage(Graphics2D graphics, Rectangle2D anchor)
      Render picture data into the supplied graphics
      Returns:
      true if the picture data was successfully rendered
    • drawImage

      boolean drawImage(Graphics2D graphics, Rectangle2D anchor, Insets clip)
      Render picture data into the supplied graphics
      Returns:
      true if the picture data was successfully rendered