public class ImagePacker extends Object
You can call create to create an image packer, initializePacking to set packing options,
addImage to add image data to be packed, and finalizePacking to complete packing and output the
target object.
SystemCapability.Multimedia#IMAGE| 限定符和类型 | 类 | 说明 |
|---|---|---|
static class |
ImagePacker.PackingOptions |
Describes options for compressing and packing.
|
| 限定符和类型 | 方法 | 说明 |
|---|---|---|
boolean |
addImage(ImageSource source) |
Adds the image in an
ImageSource to the image packer. |
boolean |
addImage(ImageSource source,
int index) |
Adds a specified image in an
ImageSource to the image packer. |
boolean |
addImage(PixelMap pixelmap) |
Adds a
PixelMap to the image packer. |
static ImagePacker |
create() |
Creates an
ImagePacker instance. |
protected void |
finalize() |
Called by the garbage collector on an object when garbage collection
determines that there are no more references to the object.
|
long |
finalizePacking() |
Completes the image packing.
|
static HashSet<String> |
getSupportedFormats() |
Obtains the supported output image formats for packing.
|
boolean |
initializePacking(byte[] data,
int offset,
ImagePacker.PackingOptions opts) |
Initializes the packing task that outputs the result to a byte array at a specific offset.
|
boolean |
initializePacking(byte[] data,
ImagePacker.PackingOptions opts) |
Initializes the packing task that outputs the result to a byte array.
|
boolean |
initializePacking(OutputStream outputStream,
ImagePacker.PackingOptions opts) |
Initializes the packing task that outputs the result to a
OutputStream object. |
void |
release() |
Releases native resources associated with the
ImagePacker object. |
public static ImagePacker create()
ImagePacker instance.ImagePacker instance if created; returns null if an exception occurs.public static HashSet<String> getSupportedFormats()
image/jpeg. Currently, only the JPEG format is supported.public boolean initializePacking(byte[] data,
ImagePacker.PackingOptions opts)
data - Indicates the byte array containing the packed images.opts - Indicates the packing options.true if the packing task is successfully initialized; returns false otherwise.IllegalArgumentException - Throws this exception if the input parameter is invalid.public boolean initializePacking(byte[] data,
int offset,
ImagePacker.PackingOptions opts)
data - Indicates the byte array containing the packed images.offset - Indicates the data array offset into which the compressed image data will be written.opts - Indicates the packing options.true if the packing task is successfully initialized; returns false otherwise.IllegalArgumentException - Throws this exception if the input parameter is invalid.public boolean initializePacking(OutputStream outputStream, ImagePacker.PackingOptions opts)
OutputStream object.outputStream - Indicates the output stream of the packed images.opts - Indicates the packing options.true if the packing task is successfully initialized; returns false otherwise.IllegalArgumentException - Throws this exception if the input parameter is invalid.public boolean addImage(PixelMap pixelmap)
pixelmap - Indicates the PixelMap to be packed.true if the pixel map is added; returns false otherwise.IllegalArgumentException - Throws this exception if the input parameter is invalid.public boolean addImage(ImageSource source)
ImageSource to the image packer.
If the ImageSource contains multiple images, only the first image will be added.
source - Indicates the ImageSource.true if the image is added; returns false otherwise.IllegalArgumentException - Throws this exception if the input parameter is invalid.public boolean addImage(ImageSource source, int index)
ImageSource to the image packer.
You can use an index to specify the image to be added.
source - Indicates the ImageSource.index - Indicates the index of the target image in the ImageSource. The value starts from 0.true if the specified image is added; returns false otherwise.IllegalArgumentException - Throws this exception if the input parameter is invalid.public long finalizePacking()
Calling this method will inform the ImagePacker that all the required image data has been
added for packing and the ImagePacker will pack the data into the specified object.
-1 otherwise.public void release()
ImagePacker object.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