Class Image

  • All Implemented Interfaces:
    java.io.Serializable

    public class Image
    extends java.lang.Object
    implements java.io.Serializable
    Provides support for in memory images. The format of the bitmap is in standard leJOS format (so aligned for use on EV3 LCD display). There is one bit per pixel. The pixels are packed into bytes with each byte spanning 8 scan lines. The least significant bit of each byte is the pixel for the top most scan line, the most significant bit is the 8th scan line. Values of 1 represent black. 0 white. This class implements a sub set of the standard lcdui Image class. Only mutable images are supported and the ARGB methods are not available. TODO: This file needs to be updated to match the EV3 image format.
    Author:
    Andre Nijholt & Andy Shaw
    See Also:
    Serialized Form
    • Constructor Summary

      Constructors 
      Constructor Description
      Image​(int width, int height, byte[] data)
      Create an image using an already existing byte array.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static Image createImage​(int width, int height)
      Create ablank image of the requested size.
      static Image createImage​(java.io.InputStream s)
      Read image from file.
      static Image createImage​(Image image, int x, int y, int w, int h, int transform)
      Creates a new image based upon the transformed region of another image
      byte[] getData()
      Return the byte array used to hold the image data.
      GraphicsLCD getGraphics()
      Returns a graphics object that can be used to draw to the image.
      int getHeight()
      return the height of the image.
      int getWidth()
      Return the width of the image.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Image

        public Image​(int width,
                     int height,
                     byte[] data)
        Create an image using an already existing byte array. The byte array is used to store the image data. The array may already be initialized with image data.
        Note: This is a non standard constructor.
        Parameters:
        width - width of the image
        height - height of the image
        data - The byte array to be used for image store/
    • Method Detail

      • createImage

        public static Image createImage​(int width,
                                        int height)
        Create ablank image of the requested size.
        Parameters:
        width -
        height -
        Returns:
        Returns the new image.
      • createImage

        public static Image createImage​(java.io.InputStream s)
                                 throws java.io.IOException
        Read image from file. An image file has the following format:
        1st byte - 4th byte 5th byte - 8th byte 9th byte 10th byte ....
        image-width (int) image-height (int) 0x00(image data delimit) byte image data....

        For example:

        After a file with content
        width (int) height (int) delimit byte data
        00 00 00 03 00 00 00 05 00 00 02 1f
        was read, this method will return an object which is equivalent to
        new Image(3, 5, new byte[] {(byte)0x00, (byte)0x02, (byte)0x1f})
        Parameters:
        s - The input stream for the image file.
        Returns:
        an ev3 image object.
        Throws:
        java.io.IOException - if an input or output error occurs or file format is not correct.
        See Also:
        Image, Image(int, int, byte[])
      • createImage

        public static Image createImage​(Image image,
                                        int x,
                                        int y,
                                        int w,
                                        int h,
                                        int transform)
        Creates a new image based upon the transformed region of another image
        Parameters:
        image - Source image
        x - x co-ordinate of the source region
        y - y co-ordinate of the source region
        w - width of the source region
        h - height of the source region
        transform - Transform to be applied
        Returns:
        New image
      • getWidth

        public int getWidth()
        Return the width of the image.
        Returns:
        Image width
      • getHeight

        public int getHeight()
        return the height of the image.
        Returns:
        image height
      • getData

        public byte[] getData()
        Return the byte array used to hold the image data.
        Note: This is a non standard method.
        Returns:
        The image byte array.
      • getGraphics

        public GraphicsLCD getGraphics()
        Returns a graphics object that can be used to draw to the image.
        Returns:
        graphics object.
        See Also:
        GraphicsLCD