Sequenceablepublic class PixelMap extends Object implements Sequenceable
Applications can use methods, such as getImageInfo(), to obtain basic image information.
SystemCapability.Multimedia#IMAGE| 限定符和类型 | 类 | 说明 |
|---|---|---|
static class |
PixelMap.InitializationOptions |
Represents pixel map initialization options, including the image size, pixel format, and alpha type.
|
Sequenceable.Producer<T>| 限定符和类型 | 字段 | 说明 |
|---|---|---|
static Sequenceable.Producer<PixelMap> |
PRODUCER |
| 限定符 | 构造器 | 说明 |
|---|---|---|
protected |
PixelMap(long nativeImagePixelMap,
long nativeAllocBytes) |
A constructor used to create a
PixelMap instance. |
| 限定符和类型 | 方法 | 说明 |
|---|---|---|
static PixelMap |
create(int[] colors,
int offset,
int stride,
PixelMap.InitializationOptions opts) |
Creates a pixel map based on initialization options (such as the image size, pixel format, and alpha type) and
the data source described by a pixel color array, start offset, and number of pixels in a row.
|
static PixelMap |
create(int[] colors,
PixelMap.InitializationOptions opts) |
Creates a pixel map based on initialization options (such as the image size, pixel format, and alpha type) and
the data source described by a pixel color array.
|
static PixelMap |
create(PixelMap.InitializationOptions opts) |
Creates a pixel map based on initialization options (such as the image size, pixel format, and alpha type).
|
static PixelMap |
create(PixelMap source,
Rect srcRegion,
PixelMap.InitializationOptions opts) |
Creates a pixel map based on initialization options (such as the image size, pixel format, and alpha type) and
the data source described by a source pixel map and the expected area on it.
|
static PixelMap |
create(PixelMap source,
PixelMap.InitializationOptions opts) |
Creates a pixel map based on initialization options (such as the image size, pixel format, and alpha type) and
the data source described by a source pixel map.
|
PixelMap |
createFromAlpha() |
Creates a
PixelMap using the alpha channel of this PixelMap. |
protected void |
finalize() |
Called by the garbage collector on an object when garbage collection
determines that there are no more references to the object.
|
int |
getBaseDensity() |
Obtains the base pixel density of this
PixelMap. |
int |
getBytesNumberPerRow() |
Obtains the number of bytes in each row of pixels.
|
Size |
getFitDensitySize(int targetDensity) |
Obtains the image size that fits the specified pixel density.
|
ImageInfo |
getImageInfo() |
Obtains basic image information.
|
byte[] |
getNinePatchChunk() |
Obtains 9 patch chunk data of this
PixelMap. |
long |
getPixelBytesCapacity() |
Obtains the memory capacity for storing the pixels of this
PixelMap. |
long |
getPixelBytesNumber() |
Obtains the pixel data size in bytes.
|
boolean |
isEditable() |
Checks whether this
PixelMap can be edited. |
boolean |
isReleased() |
Checks whether native resources have been released.
|
boolean |
isSameImage(PixelMap other) |
Checks whether this
PixelMap is the same as the specified one, including the attribute information
described by the ImageInfo instance and pixel data. |
boolean |
marshalling(Parcel out) |
|
int |
readPixel(Position pos) |
Reads the color value at the specified position.
|
void |
readPixels(int[] pixels,
int offset,
int stride,
Rect region) |
Reads the color values of a specified region and writes them into a
pixels array with the specified start
offset and stride. |
void |
readPixels(Buffer dst) |
Reads a copy of color values of this
PixelMap instance and stores it to the specified buffer. |
void |
release() |
Releases native resources associated with an object.
|
void |
resetConfig(Size size,
PixelFormat pixelFormat) |
Resets the size and pixel format of this
PixelMap. |
void |
setAlphaType(AlphaType alphaType) |
Sets the alpha type of this
PixelMap. |
void |
setBaseDensity(int baseDensity) |
Sets the base pixel density of this
PixelMap. |
void |
setUseMipmap(boolean useMipmap) |
Sets whether MIP mapping will be used for rendering this
PixelMap. |
boolean |
unmarshalling(Parcel in) |
|
boolean |
useMipmap() |
Checks whether MIP mapping will be used for rendering this
PixelMap. |
void |
writePixel(Position pos,
int color) |
Writes the color value into the specified position.
|
void |
writePixels(int color) |
Writes the specified color value into this
PixelMap. |
void |
writePixels(int[] pixels,
int offset,
int stride,
Rect region) |
Writes data from the specified color data array (based on the start offset and stride) into the specified region
of this
PixelMap. |
void |
writePixels(Buffer src) |
Writes the pixel data in the specified buffer into this
PixelMap. |
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waithasFileDescriptorpublic static final Sequenceable.Producer<PixelMap> PRODUCER
PixelMap instance from a Parcel. If the class has a final member variable whose value
cannot be changed by Sequenceable#unmarshalling.protected PixelMap(long nativeImagePixelMap,
long nativeAllocBytes)
PixelMap instance.nativeImagePixelMap - the native object pointer.nativeAllocBytes - the native object size.public static PixelMap create(int[] colors, PixelMap.InitializationOptions opts)
colors - Indicates an int array of pixel colors. Each element in the array is in PixelFormat#ARGB_8888 format.opts - Indicates initialization options of the pixel map.PixelMap instance if the creation is successful; returns null otherwise.IllegalArgumentException - Throws this exception if any of the following occurs: null.0.public static PixelMap create(int[] colors, int offset, int stride, PixelMap.InitializationOptions opts)
colors - Indicates an int array of color values. Each element in the array is in PixelFormat#ARGB_8888 format.offset - Indicates the offset from where to read pixel color data in the array.stride - Indicates the number of pixel color elements in each row of the array. The value must be greater
than or equal to the width of the pixel map to be created.opts - Indicates initialization options of the pixel map.PixelMap instance if the creation is successful; returns null otherwise.IllegalArgumentException - Throws this exception if any of the following occurs: null.0.stride is smaller
than the width of the pixel map.public static PixelMap create(PixelMap.InitializationOptions opts)
opts - Indicates initialization options of the pixel map.PixelMap instance if the creation is successful; returns null otherwise.IllegalArgumentException - Throws this exception if the image size is null, or the width and height
are less than or equal to 0.public static PixelMap create(PixelMap source, PixelMap.InitializationOptions opts)
source - Indicates the PixelMap instance as the data source.opts - Indicates initialization options of the pixel map. If the value is null, the target pixel map
will be created from a copy of the source pixel map.PixelMap instance if the creation is successful; returns null otherwise.IllegalArgumentException - Throws this exception if any of the following occurs: null.opts is less than 0.public static PixelMap create(PixelMap source, Rect srcRegion, PixelMap.InitializationOptions opts)
source - Indicates the source PixelMap.srcRegion - Indicates the expected region on the source pixel map.opts - Indicates initialization options of the pixel map. If this parameter is null, the new pixel
map will be a copy of the source pixel map.PixelMap instance if the creation is successful; returns null otherwise.IllegalArgumentException - Throws this exception if any of the following occurs: null.srcRegion is out of the source pixel map.
opts is less than 0.public ImageInfo getImageInfo()
Basic image information is provided by ImageInfo,
including the image size, pixel format, and color space.
ImageInfo object.public void release()
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,
PhantomReferencepublic byte[] getNinePatchChunk()
PixelMap.null otherwise.public boolean isReleased()
true if resources are released; returns false otherwise.public boolean marshalling(Parcel out)
marshalling 在接口中 Sequenceableout - Indicates the Parcel object to which the PixelMap object will be written.true if the marshalling is successful; returns false otherwise.public boolean unmarshalling(Parcel in)
unmarshalling 在接口中 Sequenceablein - Indicates the Parcel object into which the PixelMap object has been written.true if the marshalling is successful; returns false otherwise.public int getBytesNumberPerRow()
IllegalStateException - Throws this exception if native resources associated with this PixelMap
have been released.public long getPixelBytesNumber()
IllegalStateException - Throws this exception if native resources associated with this PixelMap
have been released.public long getPixelBytesCapacity()
PixelMap.IllegalStateException - Throws this exception if native resources associated with this PixelMap
have been released.public boolean isEditable()
PixelMap can be edited.true if the pixel map is editable; returns false otherwise.IllegalStateException - Throws this exception if native resources associated with this PixelMap
have been released.public boolean isSameImage(PixelMap other)
PixelMap is the same as the specified one, including the attribute information
described by the ImageInfo instance and pixel data.other - Indicates the specified PixelMap to compare.true if the two images are the same; returns false otherwise.IllegalArgumentException - Throws this exception if the specified PixelMap is empty.IllegalStateException - Throws this exception if native resources associated with this PixelMap
have been released.public int readPixel(Position pos)
pos - Indicates the coordinate of the pixel.AlphaType#UNPREMUL type and in PixelFormat#ARGB_8888 format.IllegalArgumentException - Throws this exception if the passed coordinate position is null or out
of the valid range of the image.IllegalStateException - Throws this exception if native resources associated with this PixelMap
have been released.public void readPixels(int[] pixels,
int offset,
int stride,
Rect region)
pixels array with the specified start
offset and stride. The color values are of the AlphaType#UNPREMUL type and in PixelFormat#ARGB_8888 format.pixels - Indicates the array storing the color value copies.offset - Indicates the offset into which the color values will be written.stride - Indicates the number of color values stored in each row of the array. The parameter value must be
greater than or equal to the width of the specified source region.region - Indicates the source region to obtain the color values.IllegalStateException - Throws this exception if native resources associated with this PixelMap
have been released.IllegalArgumentException - Throws this exception if any of the following occurs: pixels
array is null.offset value is less than 0 or larger than the pixels
array length.stride value is less than 0.region value is
null or out of the valid range of the image.ArrayIndexOutOfBoundsException - Throws this exception if the pixels array is too small to
accommodate the color values.public void readPixels(Buffer dst)
PixelMap instance and stores it to the specified buffer.dst - Indicates the buffer storing the color value copies.IllegalStateException - Throws this exception if native resources associated with this PixelMap
have been released.IllegalArgumentException - Throws this exception if the buffer is null or the format is not
supported.ArrayIndexOutOfBoundsException - Throws this exception if the size of the color values exceeds the buffer
capacity.public void resetConfig(Size size, PixelFormat pixelFormat)
PixelMap. This method does not change the original pixel data,
or reallocate the memory for storing the pixel data.size - Indicates the target image size after the reset, in bytes. The value must not exceed the memory
occupied by this PixelMap.pixelFormat - Indicates pixel format to reset.IllegalStateException - Throws this exception if native resources associated with this PixelMap
have been released, or the PixelMap cannot be edited.IllegalArgumentException - Throws this exception if the memory capacity required by the target image size
and pixel format exceeds the available capacity.public void setAlphaType(AlphaType alphaType)
PixelMap.alphaType - Indicates the AlphaType to set.IllegalStateException - Throws this exception if native resources associated with this PixelMap
have been released, or the PixelMap cannot be edited.IllegalArgumentException - Throws this exception if the input AlphaType is invalid.public void writePixel(Position pos, int color)
pos - Indicates the coordinate position to write the pixel value.color - Indicates the color value to write, which is of the AlphaType#UNPREMUL type and in PixelFormat#ARGB_8888 format.IllegalStateException - Throws this exception if native resources associated with this PixelMap
have been released, or the PixelMap cannot be edited.IllegalArgumentException - Throws this exception if the coordinate position is null or out of the
valid range of the image.public void writePixels(int[] pixels,
int offset,
int stride,
Rect region)
PixelMap. The color data to write is of the AlphaType#UNPREMUL type and in PixelFormat#ARGB_8888 format.pixels - Indicates the array of color data.offset - Indicates the offset from which the color data will be read.stride - Indicates the number of pixels in each row of the array. The value must be greater than or equal to
the width of the target region in this PixelMap.region - Indicates the target pixel map region into which the data will be written.IllegalStateException - Throws this exception if native resources associated with this PixelMap
have been released, or the PixelMap cannot be edited.IllegalArgumentException - Throws this exception if any of the following occurs: pixels
array is null.offset value is less than 0 or larger than the pixels
array length.stride value is less than 0.region value is out
of the valid range of the image.public void writePixels(Buffer src)
PixelMap. The buffer data will overwrite the
PixelMap data, so the color format of the source data must be compatible with this PixelMap.src - Indicates the buffer whose pixel data will be written.IllegalStateException - Throws this exception if native resources associated with this PixelMap
have been released, or the PixelMap cannot be edited.IllegalArgumentException - Throws this exception if the buffer is null or the format is not
supported.ArrayIndexOutOfBoundsException - Throws this exception if the data in the buffer is insufficient to fill
the PixelMap.public void writePixels(int color)
PixelMap.color - Indicates the color value to write, which is of the AlphaType#UNPREMUL type and in PixelFormat#ARGB_8888 format.IllegalStateException - Throws this exception if native resources associated with this PixelMap
have been released, or the PixelMap cannot be edited.public void setBaseDensity(int baseDensity)
PixelMap.baseDensity - Indicates the base pixel density to set.public int getBaseDensity()
PixelMap.public final void setUseMipmap(boolean useMipmap)
PixelMap.useMipmap - Specifies whether to use MIP mapping. Set it to true if the renderer will use MIP
mapping and to false otherwise.public final boolean useMipmap()
PixelMap.true if the renderer will try MIP mapping; returns false otherwise.IllegalStateException - Throws this exception if native resources associated with this PixelMap
have been released.public Size getFitDensitySize(int targetDensity)
targetDensity - Indicates the pixel density.IllegalStateException - Throws this exception if native resources associated with this PixelMap
have been released.public PixelMap createFromAlpha()
PixelMap using the alpha channel of this PixelMap.PixelMap containing only the alpha channel.