Class Image

  • All Implemented Interfaces:
    android.os.Parcelable

    public class Image
    extends java.lang.Object
    implements android.os.Parcelable
    Represents a image that is being processed.
    • Nested Class Summary

      • Nested classes/interfaces inherited from interface android.os.Parcelable

        android.os.Parcelable.ClassLoaderCreator<T extends java.lang.Object>, android.os.Parcelable.Creator<T extends java.lang.Object>
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static android.os.Parcelable.Creator<Image> CREATOR  
      • Fields inherited from interface android.os.Parcelable

        CONTENTS_FILE_DESCRIPTOR, PARCELABLE_WRITE_RETURN_VALUE
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected Image​(android.os.Parcel in)  
    • Method Summary

      All Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      Image clone()
      Creates and returns a copy of this image object.
      android.graphics.Bitmap convertToBitmap()
      Converts this image into Android Bitmap.
      int describeContents()  
      void dispose()
      Disposes native object containing image pixels.
      protected void finalize()  
      java.nio.ByteBuffer getBuffer()
      Returns the native buffer that contains image pixels.
      int getHeight()
      Returns the height of the image (corrected for the current orientation).
      ImageFormat getImageFormat()
      Returns the format of the image.
      java.lang.String getImageName()
      Deprecated.
      Do not rely on this information anymore.
      Orientation getImageOrientation()
      Returns the orientation of the image.
      ImageType getImageType()
      Returns the type of the image.
      int getPixelStride()
      Returns the pixel stride for image buffer.
      int getRawHeight()
      Returns the raw height of the image (uncorrected for the orientation)
      android.graphics.Rect getRawROI()
      Returns the region of interest in image in raw form (not corrected for orientation).
      int getRawWidth()
      Returns the raw width of the image (uncorrected for the orientation)
      android.graphics.Rect getROI()
      Returns the region of interest in image corrected for current orientation of image.
      int getRowStride()
      Returns the row stride for image buffer.
      int getWidth()
      Returns the width of the image (corrected for the current orientation).
      boolean isDisposed()
      Returns true if image's internal buffers are disposed and cannot be used anymore.
      void setImageOrientation​(Orientation orientation)
      Use this method to change Image's orientation.
      void setROI​(android.graphics.Rect roi)
      Sets the region of interest in image.
      void writeToParcel​(android.os.Parcel dest, int flags)  
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • CREATOR

        @NonNull
        public static final android.os.Parcelable.Creator<Image> CREATOR
    • Constructor Detail

      • Image

        protected Image​(@NonNull
                        android.os.Parcel in)
    • Method Detail

      • dispose

        public void dispose()
        Disposes native object containing image pixels. After this method is called, Image object cannot be used anymore.
      • finalize

        protected void finalize()
                         throws java.lang.Throwable
        Overrides:
        finalize in class java.lang.Object
        Throws:
        java.lang.Throwable
      • clone

        @NonNull
        public Image clone()
        Creates and returns a copy of this image object. This method makes a copy of image pixels. Use it if you want to use this image for later processing.
        Overrides:
        clone in class java.lang.Object
        Returns:
        a copy of this image object
      • getWidth

        public int getWidth()
        Returns the width of the image (corrected for the current orientation).
        Returns:
        the width of the image (corrected for the current orientation).
      • getRawWidth

        public int getRawWidth()
        Returns the raw width of the image (uncorrected for the orientation)
      • getHeight

        public int getHeight()
        Returns the height of the image (corrected for the current orientation).
        Returns:
        the height of the image (corrected for the current orientation).
      • getRawHeight

        public int getRawHeight()
        Returns the raw height of the image (uncorrected for the orientation)
      • getImageType

        @NonNull
        public ImageType getImageType()
        Returns the type of the image.
        Returns:
        the type of the image.
      • getImageFormat

        @NonNull
        public ImageFormat getImageFormat()
        Returns the format of the image.
        Returns:
        the format of the image.
      • getImageName

        @NonNull
        @Deprecated
        public java.lang.String getImageName()
        Deprecated.
        Do not rely on this information anymore. New API images will be nameless.
        Returns the name of the image.
        Returns:
        the name of the image.
      • getBuffer

        @NonNull
        public java.nio.ByteBuffer getBuffer()
        Returns the native buffer that contains image pixels.
        Returns:
        the native buffer that contains image pixels.
      • getPixelStride

        public int getPixelStride()
        Returns the pixel stride for image buffer. Pixel stride is byte difference between two consecutive pixels image row. It is guaranteed that pixel stride is at least 1.
        Returns:
        the pixel stride for image buffer.
      • getRowStride

        public int getRowStride()
        Returns the row stride for image buffer. Row stride is byte difference between two consecutive rows in image.
        Returns:
        the row stride for image plane
      • getROI

        @NonNull
        public android.graphics.Rect getROI()
        Returns the region of interest in image corrected for current orientation of image.
      • getRawROI

        @NonNull
        public android.graphics.Rect getRawROI()
        Returns the region of interest in image in raw form (not corrected for orientation). This is useful only for YUV_NV21 images that will contain the entire image in buffer and to obtain ROI-ed image, you should use YuvImage helper class (see: YuvImage )
        Returns:
        the region of interest in image.
      • setROI

        public void setROI​(@NonNull
                           android.graphics.Rect roi)
        Sets the region of interest in image. You can use this method to set the ROI of images that will be processed via RecognizerRunner. Coordinates of the ROI are applied in the current image's orientation - see getImageOrientation().
        Parameters:
        roi - region of interest in image
      • getImageOrientation

        @NonNull
        public Orientation getImageOrientation()
        Returns the orientation of the image. Orientation is defined as orientation of the device when the image was taken. To explain the orientation further, let's assume that image contains a line of text. If orientation is Orientation.ORIENTATION_LANDSCAPE_RIGHT, the line of text would be horizontal from left to right (normal reading orientation). If orientation is Orientation.ORIENTATION_PORTRAIT, the line of text would be vertical from bottom to top. In order to read the text, you would need to rotate image by 90 degrees clockwise. If orientation is Orientation.ORIENTATION_PORTRAIT_UPSIDE, the line of text would be vertical from top to bottom. In order to read the text, you would need to rotate image by 90 degrees counterclockwise. If orientation is Orientation.ORIENTATION_LANDSCAPE_LEFT, the line of text would be horizontal from right to left (upside down). In order to read the text, you would need to rotate image by 180 degrees.
        Returns:
        the orientation of the image
      • setImageOrientation

        public void setImageOrientation​(@NonNull
                                        Orientation orientation)
        Use this method to change Image's orientation. This can be useful for different interpretations of same image in different recognition contexts.
        Parameters:
        orientation -
      • isDisposed

        public boolean isDisposed()
        Returns true if image's internal buffers are disposed and cannot be used anymore.
        Returns:
        true if image's internal buffers are disposed and cannot be used anymore.
      • convertToBitmap

        @Nullable
        public android.graphics.Bitmap convertToBitmap()
        Converts this image into Android Bitmap. This is a very slow process that involves copying and converting a lot of data. Returned bitmap has its own pixel buffer, so it may remain valid even after this image's buffers become invalid (i.e. after image gets disposed).
        Returns:
        Image converted to Android Bitmap or null if conversion failed.
      • describeContents

        public int describeContents()
        Specified by:
        describeContents in interface android.os.Parcelable
      • writeToParcel

        public void writeToParcel​(@NonNull
                                  android.os.Parcel dest,
                                  int flags)
        Specified by:
        writeToParcel in interface android.os.Parcelable