Class ActiveGraphics2D

  • All Implemented Interfaces:
    AutoCloseable

    public final class ActiveGraphics2D
    extends Object
    implements AutoCloseable
    Wrapper for a Graphics2D instance that disposes of the instance automatically when closed. Also has static methods for creating new wrappers.
    Author:
    XIMA MEDIA GmbH
    • Method Detail

      • fromImage

        public static ActiveGraphics2D fromImage​(BufferedImage image)
        Creates and wraps a Graphics2D instance, which can be used to draw into the given BufferedImage. The wrapper returned by this method implements AutoCloseable so that you can use with try-with-resources-statements instead of having to dispose the graphics 2D instance manually.
        Parameters:
        image - Buffered image on which to draw.
        Returns:
        A Graphics2D wrapper that disposes the underlying resource automatically when closed.
      • wrap

        public static ActiveGraphics2D wrap​(Graphics2D g2d)
        Wraps a Graphics2D instance. The wrapper returned by this method implements AutoCloseable so that you can use with try-with-resources-statements instead of having to dispose the graphics 2D instance manually.
        Parameters:
        g2d - Instance to wrap.
        Returns:
        A Graphics2D wrapper that disposes the underlying resource automatically when closed.