public class ImageSource extends Object
Applications can use this class to decode image.
Create an ImageSource by calling create. Obtain basic image information by
calling getImageInfo. Decode images by calling createPixelMap.
SystemCapability.Multimedia#IMAGE| 限定符和类型 | 类 | 说明 |
|---|---|---|
static interface |
ImageSource.DecodeEventListener |
Listens for the events occurred during image decoding.
|
static class |
ImageSource.DecodingOptions |
Provides image decoding options.
|
static class |
ImageSource.IncrementalSourceOptions |
Describes options of the incremental data source.
|
static class |
ImageSource.SourceInfo |
Describes image source information, including the image quantity and file format.
|
static class |
ImageSource.SourceOptions |
Describes image data source options, including the image format represented as
image/png, for example. |
static class |
ImageSource.UpdateMode |
Describes the update mode of the image data source.
|
| 限定符和类型 | 方法 | 说明 |
|---|---|---|
static ImageSource |
create(byte[] data,
int offset,
int length,
ImageSource.SourceOptions opts) |
Creates an
ImageSource based on a byte array with specified offset and length. |
static ImageSource |
create(byte[] data,
ImageSource.SourceOptions opts) |
Creates an
ImageSource based on a byte array. |
static ImageSource |
create(FileDescriptor fd,
ImageSource.SourceOptions opts) |
Creates an
ImageSource based on a file descriptor. |
static ImageSource |
create(File file,
ImageSource.SourceOptions opts) |
Creates an
ImageSource based on a File object. |
static ImageSource |
create(InputStream is,
ImageSource.SourceOptions opts) |
Creates an
ImageSource based on an input stream. |
static ImageSource |
create(String pathName,
ImageSource.SourceOptions opts) |
Creates an
ImageSource based on an image file path. |
static ImageSource |
create(ByteBuffer data,
ImageSource.SourceOptions opts) |
Creates an
ImageSource based on a ByteBuffer and source options. |
static ImageSource |
create(Callable<RawFileDescriptor> callable,
ImageSource.SourceOptions opts) |
|
static ImageSource |
createIncrementalSource(ImageSource.IncrementalSourceOptions opts) |
Creates an incremental data source based on an
IncrementalSourceOptions object. |
static ImageSource |
createIncrementalSource(ImageSource.SourceOptions opts) |
Creates an incremental data source based on a
SourceOptions object. |
PixelMap |
createPixelmap(int index,
ImageSource.DecodingOptions opts) |
Decodes source image data based on a specified index location in the
ImageSource and creates a pixel
map. |
PixelMap |
createPixelmap(ImageSource.DecodingOptions opts) |
Decodes source image data and creates a pixel map.
|
PixelMap |
createThumbnailPixelmap(ImageSource.DecodingOptions opts,
boolean allowFromImage) |
Decodes thumbnail data contained in the
ImageSource instance to generate a thumbnail and creates a
thumbnail pixel map. |
protected void |
finalize() |
Called by the garbage collector on an object when garbage collection
determines that there are no more references to the object.
|
ImageInfo |
getImageInfo() |
Obtains basic image information.
|
ImageInfo |
getImageInfo(int index) |
Obtains basic information about the image at a specified index.
|
int |
getImagePropertyInt(int index,
String key,
int defaultValue) |
Obtains the integer value of a specified property key for an image at the given index in the
ImageSource. |
int |
getImagePropertyInt(String key,
int defaultValue) |
Obtains the integer value of a specified image property key.
|
String |
getImagePropertyString(String key) |
Obtains the string value of a specified image property key.
|
byte[] |
getImageThumbnailBytes() |
Obtains raw data of the thumbnail from the
ImageSource instance. |
byte[] |
getInnerJpegThumbnail() |
Obtains the byte data of the JPEG thumbnail stored in the Exif information
about this JPEG
ImageSource instance. |
long[] |
getInnerThumbnailScope() |
Obtains the start position and data length of the thumbnail data saved in the
Exif information about this JPEG
ImageSource instance. |
ImageSource.SourceInfo |
getSourceInfo() |
Obtains image source information.
|
static HashSet<String> |
getSupportedFormats() |
Obtains supported image formats for decoding, which are represented by MIME type strings.
|
int |
getThumbnailFormat() |
Obtains the format of the thumbnail from the
ImageSource instance. |
ImageInfo |
getThumbnailInfo() |
Obtains basic information (such as the size) about the thumbnail from the
ImageSource instance. |
boolean |
isReleased() |
Used to determine if the native resources of the Image Source has been released.
|
void |
release() |
Releases native resources associated with an object.
|
void |
setDecodeEventListener(ImageSource.DecodeEventListener listener) |
Sets a listener for observing decoding events.
|
void |
setMemoryUsagePreference(MemoryUsagePreference preference) |
Sets memory use preference.
|
boolean |
updateData(byte[] data,
boolean isFinal) |
Updates incremental data to an image data source using a byte array.
|
boolean |
updateData(byte[] data,
int offset,
int length,
boolean isFinal) |
Updates incremental data to an image data source using a byte array with specified offset and length.
|
public static HashSet<String> getSupportedFormats()
public void setDecodeEventListener(ImageSource.DecodeEventListener listener)
listener - Indicates the listener to set.public void setMemoryUsagePreference(MemoryUsagePreference preference)
preference - Indicates the preference to set,
which is defined in MemoryUsagePreference.public static ImageSource create(InputStream is, ImageSource.SourceOptions opts)
ImageSource based on an input stream.
This method takes an InputStream instance as the source where the image data derives from. The
ImageSource instance to create cannot be used to obtain Exif information.
is - Indicates an input stream of the image data source.opts - Indicates data source options.ImageSource object if created; returns null if an exception occurs.IllegalArgumentException - Throws this exception if the input parameter is invalid.public static ImageSource create(byte[] data, ImageSource.SourceOptions opts)
ImageSource based on a byte array.data - Indicates the byte array containing the source data.opts - Indicates data source options.ImageSource object if created; returns null if an exception occurs.IllegalArgumentException - Throws this exception if the input parameter is invalid.public static ImageSource create(ByteBuffer data, ImageSource.SourceOptions opts)
ImageSource based on a ByteBuffer and source options.data - Indicates the ByteBuffer that contains the image source data.opts - Indicates the source options.ImageSource if the creation is successful; returns null otherwise.IllegalArgumentException - Throws this exception if an input parameter is invalid.public static ImageSource create(Callable<RawFileDescriptor> callable, ImageSource.SourceOptions opts)
callable - Indicates the object that implements the Callable interface.opts - Indicates the source options.ImageSource if the creation is successful; returns null otherwise.IllegalArgumentException - Throws this exception if an input parameter is invalid.public static ImageSource create(byte[] data, int offset, int length, ImageSource.SourceOptions opts)
ImageSource based on a byte array with specified offset and length.data - Indicates the byte array containing the source data.offset - Indicates the offset into image data for where the reading begins.length - Indicates the image data size, in bytes.opts - Indicates data source options.ImageSource object if created; returns null if an exception occurs.IllegalArgumentException - Throws this exception if the input parameter is invalid.IndexOutOfBoundsException - Throws this exception if the offset or length is invalid.public static ImageSource create(String pathName, ImageSource.SourceOptions opts)
ImageSource based on an image file path.pathName - Indicates the file path based on which the ImageSource is created.opts - Indicates data source options.ImageSource object if created; returns null if an exception occurs.IllegalArgumentException - Throws this exception if the input parameter is invalid.public static ImageSource create(File file, ImageSource.SourceOptions opts)
ImageSource based on a File object.file - Indicates a File object.opts - Indicates data source options.ImageSource object if created; returns null if an exception occurs.IllegalArgumentException - Throws this exception if the input parameter is invalid.public static ImageSource create(FileDescriptor fd, ImageSource.SourceOptions opts)
ImageSource based on a file descriptor.
This method takes a FileDescriptor instance as the source where the image data derives from. The
ImageSource instance to create cannot be used to obtain Exif information.
fd - Indicates the descriptor of an image source file.opts - Indicates data source options.ImageSource object if created; returns null if an exception occurs.IllegalArgumentException - Throws this exception if the input parameter is invalid.public static ImageSource createIncrementalSource(ImageSource.SourceOptions opts)
SourceOptions object.
This method is used with ImageSource#updateData(byte[], int, int, boolean) to update incremental
data.
opts - Indicates data source options.ImageSource object if created; returns null if an exception occurs.IllegalArgumentException - Throws this exception if the input parameter is invalid.public static ImageSource createIncrementalSource(ImageSource.IncrementalSourceOptions opts)
IncrementalSourceOptions object.
This method is used with ImageSource#updateData(byte[], int, int, boolean) to update incremental
data.
opts - Indicates incremental data source options.ImageSource object if created; returns null if an exception occurs.IllegalArgumentException - Throws this exception if the input parameter is invalid.public PixelMap createPixelmap(ImageSource.DecodingOptions opts)
For a source containing multiple images, the image data of index 0 is decoded by default.
opts - Indicates image decoding options.null if an exception occurs.IllegalArgumentException - Throws this exception if the input parameter is invalid.public PixelMap createPixelmap(int index, ImageSource.DecodingOptions opts)
ImageSource and creates a pixel
map.
For a source containing multiple images, use an index to specify the image location.
index - Indicates an index specifying the image location. The index starts from 0.opts - Indicates image decoding options.null if an exception occurs.IllegalArgumentException - Throws this exception if the input parameter is invalid.public PixelMap createThumbnailPixelmap(ImageSource.DecodingOptions opts, boolean allowFromImage)
ImageSource instance to generate a thumbnail and creates a
thumbnail pixel map.opts - Indicates image decoding options.allowFromImage - Specifies whether to allow creation based on the original image if the ImageSource
does not contain thumbnail data.PixelMap if the decoding is successful; returns null if the decoding
fails.IllegalArgumentException - Throws this exception if the input parameter is invalid.IllegalStateException - Throws this exception if native resources associated with this ImageSource
have been released.public boolean updateData(byte[] data,
boolean isFinal)
When incremental data is obtained, use this method to update source data.
Input data requirements are described by UpdateMode.
data - Indicates the byte array inputting incremental data.isFinal - Indicates whether the data update is the last batch.true if the source data is updated; returns false otherwise.IllegalArgumentException - Throws this exception if the input parameter is invalid.public boolean updateData(byte[] data,
int offset,
int length,
boolean isFinal)
When incremental data is obtained, use this method to update source data.
Input data requirements are described by UpdateMode.
data - Indicates the byte array inputting incremental data.offset - Indicates offset into image data for where the reading starts.length - Indicates the size of the incremental data, in bytes.isFinal - Indicates whether the data is the last batch.true if the data is updated; returns false otherwise.IllegalArgumentException - Throws this exception if the input parameter is invalid.IndexOutOfBoundsException - Throws this exception if the offset or length is invalid.public ImageInfo getImageInfo()
ImageInfo object if obtained; returns null otherwise.
Note that the returned ImageInfo object contains only the ImageInfo.size
of this ImageSource object. Other image information can be obtained only after image decoding.public ImageInfo getImageInfo(int index)
index - Indicates the image index, which starts from 0.ImageInfo object if obtained; returns null otherwise.
Note that the returned ImageInfo object contains only the ImageInfo.size
of this ImageSource object. Other image information can be obtained only after image decoding.IllegalArgumentException - Throws this exception if the input parameter is invalid.public final String getImagePropertyString(String key)
key - Indicates a key defined in PropertyKey.null if the property does not exist.IllegalStateException - Throws this exception if native resources associated with this ImageSource
instance have been released.IllegalArgumentException - Throws this exception if key is null.public final int getImagePropertyInt(String key, int defaultValue)
key - Indicates a key defined in PropertyKey.defaultValue - Indicates the custom default value of the property key.IllegalStateException - Throws this exception if native resources associated with this ImageSource
instance have been released.IllegalArgumentException - Throws this exception if key is null.public final int getImagePropertyInt(int index,
String key,
int defaultValue)
ImageSource.index - Indicates an index specifying the image location. The index starts from 0.key - Indicates a key defined in PropertyKey.defaultValue - Indicates the custom default value of the property key.IllegalStateException - Throws this exception if native resources associated with this ImageSource
instance have been released.IllegalArgumentException - Throws this exception if key is null.public ImageInfo getThumbnailInfo()
ImageSource instance.
Currently, only thumbnails in JPEG format can be identified.
null if the thumbnail is not in JPEG format.IllegalStateException - Throws this exception if native resources associated with this ImageSource
instance have been released.UnsupportedOperationException - Throws this exception if the source image file does not contain a
thumbnail.public byte[] getInnerJpegThumbnail()
ImageSource instance.byte array containing the thumbnail data if the
Exif information of this JPEG ImageSource instance contains a
thumbnail in JPEG format; returns null if the Exif
information does not contain a thumbnail or the thumbnail is not a
JPEG file.IllegalStateException - IllegalStateException Throws this exception if
this ImageSource instance:
public long[] getInnerThumbnailScope()
ImageSource instance.long array containing the start position of the
thumbnail data and the data length if the Exif information of this
JPEG ImageSource instance has thumbnail data; returns
null if there is no thumbnail data in the Exif information or
the thumbnail data is discrete.IllegalStateException - Throws this exception if this
ImageSource instance:
public byte[] getImageThumbnailBytes()
ImageSource instance.IllegalStateException - Throws this exception if native resources associated with this ImageSource
instance have been released.UnsupportedOperationException - Throws this exception if the source image file does not contain a
thumbnail.public int getThumbnailFormat()
ImageSource instance. Currently, only thumbnails in JPEG format can be identified.
ImageFormat.JPEG if the thumbnail is in JPEG format; returns
ImageFormat.UNKNOWN otherwise.IllegalStateException - Throws this exception if native resources associated with this ImageSource
have been released.UnsupportedOperationException - Throws this exception if the source image file does not contain a
thumbnail.public ImageSource.SourceInfo getSourceInfo()
null if an exception occurs.public void release()
public boolean isReleased()
protected void finalize()
throws Throwable
Objectfinalize method to dispose of
system resources or to perform other cleanup.
The general contract of finalize is that it is invoked
if and when the Java™ virtual
machine has determined that there is no longer any
means by which this object can be accessed by any thread that has
not yet died, except as a result of an action taken by the
finalization of some other object or class which is ready to be
finalized. The finalize method may take any action, including
making this object available again to other threads; the usual purpose
of finalize, however, is to perform cleanup actions before
the object is irrevocably discarded. For example, the finalize method
for an object that represents an input/output connection might perform
explicit I/O transactions to break the connection before the object is
permanently discarded.
The finalize method of class Object performs no
special action; it simply returns normally. Subclasses of
Object may override this definition.
The Java programming language does not guarantee which thread will
invoke the finalize method for any given object. It is
guaranteed, however, that the thread that invokes finalize will not
be holding any user-visible synchronization locks when finalize is
invoked. If an uncaught exception is thrown by the finalize method,
the exception is ignored and finalization of that object terminates.
After the finalize method has been invoked for an object, no
further action is taken until the Java virtual machine has again
determined that there is no longer any means by which this object can
be accessed by any thread that has not yet died, including possible
actions by other objects or classes which are ready to be finalized,
at which point the object may be discarded.
The finalize method is never invoked more than once by a Java
virtual machine for any given object.
Any exception thrown by the finalize method causes
the finalization of this object to be halted, but is otherwise
ignored.
finalize 在类中 ObjectThrowable - the Exception raised by this methodWeakReference,
PhantomReference