public class

EncodedImage

extends Object
implements Closeable
java.lang.Object
   ↳ com.facebook.imagepipeline.image.EncodedImage

Class Overview

Class that contains all the information for an encoded image, both the image bytes (held on a byte buffer or a supplier of input streams) and the extracted meta data that is useful for image transforms.

Only one of the input stream supplier or the byte buffer can be set. If using an input stream supplier, the methods that return a byte buffer will simply return null. However, getInputStream will always be supported, either from the supplier or an input stream created from the byte buffer held.

Currently the data is useful for rotation and resize.

Summary

Constants
int DEFAULT_SAMPLE_SIZE
int UNKNOWN_HEIGHT
int UNKNOWN_ROTATION_ANGLE
int UNKNOWN_STREAM_SIZE
int UNKNOWN_WIDTH
Public Constructors
EncodedImage(CloseableReference<PooledByteBuffer> pooledByteBufferRef)
EncodedImage(Supplier<FileInputStream> inputStreamSupplier)
EncodedImage(Supplier<FileInputStream> inputStreamSupplier, int streamSize)
Public Methods
EncodedImage cloneOrNull()
static EncodedImage cloneOrNull(EncodedImage encodedImage)
Returns the cloned encoded image if the parameter received is not null, null otherwise.
void close()
Closes the buffer enclosed by this class.
static void closeSafely(EncodedImage encodedImage)
Closes the encoded image handling null.
void copyMetaDataFrom(EncodedImage encodedImage)
Copy the meta data from another EncodedImage.
CloseableReference<PooledByteBuffer> getByteBufferRef()
Returns a cloned reference to the stored encoded bytes.
BytesRange getBytesRange()
ColorSpace getColorSpace()
The color space is always null if Android API level < 26.
int getExifOrientation()
Returns the exif orientation if known (1 - 8), else 0.
String getFirstBytesAsHexString(int length)
Returns first n bytes of encoded image as hexbytes
int getHeight()
Returns the image height if known, else -1.
ImageFormat getImageFormat()
Returns the image format if known, otherwise ImageFormat.UNKNOWN.
InputStream getInputStream()
Returns an InputStream from the internal InputStream Supplier if it's not null.
int getRotationAngle()
int getSampleSize()
Only valid if the image format is JPEG.
int getSize()
Returns the size of the backing structure.
synchronized SharedReference<PooledByteBuffer> getUnderlyingReferenceTestOnly()
A test-only method to get the underlying references.
int getWidth()
Returns the image width if known, else -1.
boolean isCompleteAt(int length)
Returns true if the image is a JPEG or DNG and its data is already complete at the specified length, false otherwise.
static boolean isMetaDataAvailable(EncodedImage encodedImage)
Returns true if all the image information has loaded, false otherwise.
synchronized boolean isValid()
Returns true if the internal buffer reference is valid or the InputStream Supplier is not null, false otherwise.
static boolean isValid(EncodedImage encodedImage)
Checks if the encoded image is valid i.e.
void parseMetaData()
void setBytesRange(BytesRange bytesRange)
void setExifOrientation(int exifOrientation)
Sets the exif orientation
void setHeight(int height)
Sets the image height
void setImageFormat(ImageFormat imageFormat)
Sets the image format
void setRotationAngle(int rotationAngle)
Sets the image rotation angle
void setSampleSize(int sampleSize)
Sets the image sample size
void setStreamSize(int streamSize)
Sets the size of an image if backed by an InputStream

Ignored if backed by a ByteBuffer

static void setUseCachedMetadata(boolean useCachedMetadata)
void setWidth(int width)
Sets the image width
Protected Methods
boolean hasParsedMetaData()
[Expand]
Inherited Methods
From class java.lang.Object
From interface java.io.Closeable
From interface java.lang.AutoCloseable

Constants

public static final int DEFAULT_SAMPLE_SIZE

Constant Value: 1 (0x00000001)

public static final int UNKNOWN_HEIGHT

Constant Value: -1 (0xffffffff)

public static final int UNKNOWN_ROTATION_ANGLE

Constant Value: -1 (0xffffffff)

public static final int UNKNOWN_STREAM_SIZE

Constant Value: -1 (0xffffffff)

public static final int UNKNOWN_WIDTH

Constant Value: -1 (0xffffffff)

Public Constructors

public EncodedImage (CloseableReference<PooledByteBuffer> pooledByteBufferRef)

public EncodedImage (Supplier<FileInputStream> inputStreamSupplier)

public EncodedImage (Supplier<FileInputStream> inputStreamSupplier, int streamSize)

Public Methods

public EncodedImage cloneOrNull ()

public static EncodedImage cloneOrNull (EncodedImage encodedImage)

Returns the cloned encoded image if the parameter received is not null, null otherwise.

Parameters
encodedImage the EncodedImage to clone

public void close ()

Closes the buffer enclosed by this class.

public static void closeSafely (EncodedImage encodedImage)

Closes the encoded image handling null.

Parameters
encodedImage the encoded image to close.

public void copyMetaDataFrom (EncodedImage encodedImage)

Copy the meta data from another EncodedImage.

Parameters
encodedImage the EncodedImage to copy the meta data from.

public CloseableReference<PooledByteBuffer> getByteBufferRef ()

Returns a cloned reference to the stored encoded bytes.

The caller has to close the reference once it has finished using it.

public BytesRange getBytesRange ()

public ColorSpace getColorSpace ()

The color space is always null if Android API level < 26.

Returns
  • the color space of the image if known, else null.

public int getExifOrientation ()

Returns the exif orientation if known (1 - 8), else 0.

public String getFirstBytesAsHexString (int length)

Returns first n bytes of encoded image as hexbytes

Parameters
length the number of bytes to return

public int getHeight ()

Returns the image height if known, else -1.

public ImageFormat getImageFormat ()

Returns the image format if known, otherwise ImageFormat.UNKNOWN.

public InputStream getInputStream ()

Returns an InputStream from the internal InputStream Supplier if it's not null. Otherwise returns an InputStream for the internal buffer reference if valid and null otherwise.

The caller has to close the InputStream after using it.

public int getRotationAngle ()

Returns
  • the rotation angle if the rotation angle is known, else -1. The rotation angle may not be known if the image is incomplete (e.g. for progressive JPEGs).

public int getSampleSize ()

Only valid if the image format is JPEG.

Returns
  • sample size of the image.

public int getSize ()

Returns the size of the backing structure.

If it's a PooledByteBuffer returns its size if its not null, -1 otherwise. If it's an InputStream, return the size if it was set, -1 otherwise.

public synchronized SharedReference<PooledByteBuffer> getUnderlyingReferenceTestOnly ()

A test-only method to get the underlying references.

DO NOT USE in application code.

public int getWidth ()

Returns the image width if known, else -1.

public boolean isCompleteAt (int length)

Returns true if the image is a JPEG or DNG and its data is already complete at the specified length, false otherwise.

public static boolean isMetaDataAvailable (EncodedImage encodedImage)

Returns true if all the image information has loaded, false otherwise.

public synchronized boolean isValid ()

Returns true if the internal buffer reference is valid or the InputStream Supplier is not null, false otherwise.

public static boolean isValid (EncodedImage encodedImage)

Checks if the encoded image is valid i.e. is not null, and is not closed.

Returns
  • true if the encoded image is valid

public void parseMetaData ()

public void setBytesRange (BytesRange bytesRange)

public void setExifOrientation (int exifOrientation)

Sets the exif orientation

public void setHeight (int height)

Sets the image height

public void setImageFormat (ImageFormat imageFormat)

Sets the image format

public void setRotationAngle (int rotationAngle)

Sets the image rotation angle

public void setSampleSize (int sampleSize)

Sets the image sample size

public void setStreamSize (int streamSize)

Sets the size of an image if backed by an InputStream

Ignored if backed by a ByteBuffer

public static void setUseCachedMetadata (boolean useCachedMetadata)

public void setWidth (int width)

Sets the image width

Protected Methods

protected boolean hasParsedMetaData ()