Class BufferedImage

  • All Implemented Interfaces:
    Closeable, AutoCloseable

    public class BufferedImage
    extends ResourceImage
    A BufferedImage represents a mutable image backed by a pixel buffer.

    The constructor of this class allows to create an image with given dimensions and format.

    • Constructor Detail

      • BufferedImage

        public BufferedImage​(int width,
                             int height)
        Creates a buffered image with the same format as the display.

        Equivalent to calling BufferedImage(int, int, Format) with Format.DISPLAY as parameter.

        The output format of the new image matches the pixel organization (layout, depth, etc.) of the default display.

        Parameters:
        width - the width of the new image, in pixels.
        height - the height of the new image, in pixels.
        Throws:
        IllegalArgumentException - if either width or height is negative or zero.
        MicroUIException - if the image could not be created.
        MicroUIException - if MicroUI is not started.
        SecurityException - if a security manager exists and does not allow the caller to create an image.
      • BufferedImage

        public BufferedImage​(int width,
                             int height,
                             Format format)
        Creates a buffered image specifying its format.

        The new image is initialized with unspecified data.

        Creating images is not supported by every MicroUI implementation. If the MicroUI implementation does not support the allocation of memory in order to store the image buffer or if the format is not supported, a MicroUIException is thrown.

        An image with a custom format can be based on pixels (as the standard formats) but can also be based on anything else. For instance, it can save the list of drawings and replay them when the image is drawn.

        Parameters:
        width - the width of the new image, in pixels.
        height - the height of the new image, in pixels.
        format - the format of the new image.
        Throws:
        IllegalArgumentException - if either width or height is negative or zero or is greater than implementation limit.
        MicroUIException - if there is not enough room to allocate the buffer.
        MicroUIException - if the format is not supported.
        MicroUIException - if MicroUI is not started.
        SecurityException - if a security manager exists and does not allow the caller to create an image.
    • Method Detail

      • getGraphicsContext

        public GraphicsContext getGraphicsContext()
        Gets the GraphicsContext associated with this image, which may be used in order to draw on the image.

        This method always returns the same GraphicsContext instance for a specific image. The graphics context has the same dimensions as the image, which allows to modify every pixel of the image.

        Returns:
        the image's graphics context.
        Throws:
        MicroUIException - if this image has been closed (see ResourceImage.close()).
      • getFormat

        public Format getFormat()
        Gets the format of this image.
        Returns:
        the format of this image.