Package org.bzdev.gio

Class OSGBufferedImage

All Implemented Interfaces:
RenderedImage, WritableRenderedImage, Transparency, GraphicsCreator, OSGraphicsOps

public class OSGBufferedImage extends BufferedImage implements OSGraphicsOps
Class to create a buffered image backed by an instance of OutputStreamGraphics. The method imageComplete() must be called when an image is complete: otherwise the image file may not be completely written or may not be written at all.
  • Constructor Details

    • OSGBufferedImage

      public OSGBufferedImage(OutputStreamGraphics osg)
      Constructor.
      Parameters:
      osg - the output-stream graphics used to output images
  • Method Details

    • createGraphics

      public Graphics2D createGraphics()
      Description copied from interface: OSGraphicsOps
      Get a graphics context for drawing. The graphics context created is not valid after OSGraphicsOps.flush() or OSGraphicsOps.reset() is called.
      Specified by:
      createGraphics in interface GraphicsCreator
      Specified by:
      createGraphics in interface OSGraphicsOps
      Overrides:
      createGraphics in class BufferedImage
      Returns:
      a new graphics context.
    • getGraphics

      public Graphics getGraphics()
      Overrides:
      getGraphics in class BufferedImage
    • canReset

      public boolean canReset()
      Description copied from interface: OSGraphicsOps
      Test if the method OSGraphicsOps.reset() is supported.
      Specified by:
      canReset in interface OSGraphicsOps
      Returns:
      true if OSGraphicsOps.reset() is supported; false otherwise
    • close

      public void close() throws IOException
      Description copied from interface: OSGraphicsOps
      Close resources. Typically this method will perform some action when a class that implements this interface has an associated output stream or a resource that can be closed. If there are no such resources, this method should simply return. Classes that implement this method should document what they actually do.
      Specified by:
      close in interface OSGraphicsOps
      Throws:
      IOException - if an IO error occurred
    • flush

      public void flush()
      Description copied from interface: OSGraphicsOps
      Flush the output. This method will provide a partial image or partial graphics if possible or feasible. After this method is called, the user must not use graphics contexts that were previously created. Whether this method performs any action depends on the implementation of each class or subclass implementing this interface.
      Specified by:
      flush in interface OSGraphicsOps
      Overrides:
      flush in class Image
      See Also:
    • imageComplete

      public void imageComplete() throws IOException
      Description copied from interface: OSGraphicsOps
      Final processing for writing an image file to the output stream. This method does not close an IO stream, but will flush it.

      Subclasses should implement this method so that it throws an exception if called multiple times without a successful intervening call to OSGraphicsOps.reset(). The method OSGraphicsOps.canReset() can be called to test if resets are allowed.

      Specified by:
      imageComplete in interface OSGraphicsOps
      Throws:
      IOException - IO failure, or a PrintException (which will be provided as the cause of the IOException), or an indication that this method was called multiple times
    • requestsAlpha

      public boolean requestsAlpha()
      Description copied from interface: OSGraphicsOps
      Determine if this instance is requesting an alpha channel. The value may be changed from that provided in the constructor due to the capabilities of a particular image format.
      Specified by:
      requestsAlpha in interface OSGraphicsOps
      Returns:
      true if an alpha channel is requested; false otherwise
    • reset

      public void reset() throws UnsupportedOperationException
      Description copied from interface: OSGraphicsOps
      Reset this graphics output stream. This is an optional operation as it is appropriate for some graphics output streams but not others
      Specified by:
      reset in interface OSGraphicsOps
      Throws:
      UnsupportedOperationException - an instance does not support resets