java.lang.Object | |
↳ | android.graphics.Bitmap |
Nested Classes | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Bitmap.CompressFormat | Specifies the known formats a bitmap can be compressed into | ||||||||||
Bitmap.Config |
Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Creator<Bitmap> | CREATOR |
[Expand]
Inherited Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From interface
android.os.Parcelable
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Write a compressed version of the bitmap to the specified outputstream.
| |||||||||||
Tries to make a new bitmap based on the dimensions of this bitmap,
setting the new bitmap's config to the one specified, and then copying
this bitmap's pixels into the new bitmap.
| |||||||||||
Copy the pixels from the buffer, beginning at the current position,
overwriting the bitmap's pixels.
| |||||||||||
Copy the bitmap's pixels into the specified buffer (allocated by the
caller).
| |||||||||||
Returns an immutable bitmap from the source bitmap.
| |||||||||||
Returns a immutable bitmap with the specified width and height, with each
pixel value set to the corresponding value in the colors array.
| |||||||||||
Returns a immutable bitmap with the specified width and height, with each
pixel value set to the corresponding value in the colors array.
| |||||||||||
Returns an immutable bitmap from subset of the source bitmap,
transformed by the optional matrix.
| |||||||||||
Returns a mutable bitmap with the specified width and height.
| |||||||||||
Returns an immutable bitmap from the specified subset of the source
bitmap.
| |||||||||||
No special parcel contents.
| |||||||||||
Fills the bitmap's pixels with the specified Color.
| |||||||||||
Returns a new bitmap that captures the alpha values of the original.
| |||||||||||
Returns a new bitmap that captures the alpha values of the original.
| |||||||||||
If the bitmap's internal config is in one of the public formats, return
that config, otherwise return null.
| |||||||||||
Returns the bitmap's height
| |||||||||||
Returns an optional array of private data, used by the UI system for
some bitmaps.
| |||||||||||
Returns the Color at the specified location.
| |||||||||||
Returns in pixels[] a copy of the data in the bitmap.
| |||||||||||
Return the number of bytes between rows in the bitmap's pixels.
| |||||||||||
Returns the bitmap's width
| |||||||||||
Returns true if the bitmap's pixels support levels of alpha
| |||||||||||
Returns true if the bitmap is marked as mutable (i.e.
| |||||||||||
Returns true if this bitmap has been recycled.
| |||||||||||
Free up the memory associated with this bitmap's pixels, and mark the
bitmap as "dead", meaning it will throw an exception if getPixels() or
setPixels() is called, and will draw nothing.
| |||||||||||
Write the specified Color into the bitmap (assuming it is
mutable) at the x,y coordinate.
| |||||||||||
Replace pixels in the bitmap with the colors in the array.
| |||||||||||
Write the bitmap and its pixels to the parcel.
|
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Is called before the object's memory is being reclaimed by the VM.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class java.lang.Object
| |||||||||||
From interface android.os.Parcelable
|
Write a compressed version of the bitmap to the specified outputstream. If this returns true, the bitmap can be reconstructed by passing a corresponding inputstream to BitmapFactory.decodeStream(). Note: not all Formats support all bitmap configs directly, so it is possible that the returned bitmap from BitmapFactory could be in a different bitdepth, and/or may have lost per-pixel alpha (e.g. JPEG only supports opaque pixels).
format | The format of the compressed image |
---|---|
quality | Hint to the compressor, 0-100. 0 meaning compress for small size, 100 meaning compress for max quality. Some formats, like PNG which is lossless, will ignore the quality setting |
stream | The outputstream to write the compressed data. |
Tries to make a new bitmap based on the dimensions of this bitmap, setting the new bitmap's config to the one specified, and then copying this bitmap's pixels into the new bitmap. If the conversion is not supported, or the allocator fails, then this returns NULL.
config | The desired config for the resulting bitmap |
---|---|
isMutable | True if the resulting bitmap should be mutable (i.e. its pixels can be modified) |
Copy the pixels from the buffer, beginning at the current position, overwriting the bitmap's pixels. The data in the buffer is not changed in any way (unlike setPixels(), which converts from unpremultipled 32bit to whatever the bitmap's native format is.
Copy the bitmap's pixels into the specified buffer (allocated by the caller). An exception is thrown if the buffer is not large enough to hold all of the pixels (taking into account the number of bytes per pixel) or if the Buffer subclass is not one of the support types (ByteBuffer, ShortBuffer, IntBuffer).
Returns an immutable bitmap from the source bitmap. The new bitmap may be the same object as source, or a copy may have been made.
Returns a immutable bitmap with the specified width and height, with each pixel value set to the corresponding value in the colors array.
colors | Array of Color used to initialize the pixels. This array must be at least as large as width * height. |
---|---|
width | The width of the bitmap |
height | The height of the bitmap |
config | The bitmap config to create. If the config does not support per-pixel alpha (e.g. RGB_565), then the alpha bytes in the colors[] will be ignored (assumed to be FF) |
IllegalArgumentException | if the width or height are <= 0, or if the color array's length is less than the number of pixels. |
---|
Returns a immutable bitmap with the specified width and height, with each pixel value set to the corresponding value in the colors array.
colors | Array of Color used to initialize the pixels. |
---|---|
offset | Number of values to skip before the first color in the array of colors. |
stride | Number of colors in the array between rows (must be >= width or <= -width). |
width | The width of the bitmap |
height | The height of the bitmap |
config | The bitmap config to create. If the config does not support per-pixel alpha (e.g. RGB_565), then the alpha bytes in the colors[] will be ignored (assumed to be FF) |
IllegalArgumentException | if the width or height are <= 0, or if the color array's length is less than the number of pixels. |
---|
Returns an immutable bitmap from subset of the source bitmap, transformed by the optional matrix.
source | The bitmap we are subsetting |
---|---|
x | The x coordinate of the first pixel in source |
y | The y coordinate of the first pixel in source |
width | The number of pixels in each row |
height | The number of rows |
m | Option matrix to be applied to the pixels |
filter | true if the source should be filtered. Only applies if the matrix contains more than just translation. |
IllegalArgumentException | if the x, y, width, height values are outside of the dimensions of the source bitmap. |
---|
Returns a mutable bitmap with the specified width and height.
width | The width of the bitmap |
---|---|
height | The height of the bitmap |
config | The bitmap config to create. |
IllegalArgumentException | if the width or height are <= 0 |
---|
Returns an immutable bitmap from the specified subset of the source bitmap. The new bitmap may be the same object as source, or a copy may have been made.
source | The bitmap we are subsetting |
---|---|
x | The x coordinate of the first pixel in source |
y | The y coordinate of the first pixel in source |
width | The number of pixels in each row |
height | The number of rows |
No special parcel contents.
Fills the bitmap's pixels with the specified Color.
IllegalStateException | if the bitmap is not mutable. |
---|
Returns a new bitmap that captures the alpha values of the original. This may be drawn with Canvas.drawBitmap(), where the color(s) will be taken from the paint that is passed to the draw call.
Returns a new bitmap that captures the alpha values of the original. These values may be affected by the optional Paint parameter, which can contain its own alpha, and may also contain a MaskFilter which could change the actual dimensions of the resulting bitmap (e.g. a blur maskfilter might enlarge the resulting bitmap). If offsetXY is not null, it returns the amount to offset the returned bitmap so that it will logically align with the original. For example, if the paint contains a blur of radius 2, then offsetXY[] would contains -2, -2, so that drawing the alpha bitmap offset by (-2, -2) and then drawing the original would result in the blur visually aligning with the original.
paint | Optional paint used to modify the alpha values in the resulting bitmap. Pass null for default behavior. |
---|---|
offsetXY | Optional array that returns the X (index 0) and Y (index 1) offset needed to position the returned bitmap so that it visually lines up with the original. |
If the bitmap's internal config is in one of the public formats, return that config, otherwise return null.
Returns the bitmap's height
Returns an optional array of private data, used by the UI system for some bitmaps. Not intended to be called by applications.
Returns the Color at the specified location. Throws an exception if x or y are out of bounds (negative or >= to the width or height respectively).
x | The x coordinate (0...width-1) of the pixel to return |
---|---|
y | The y coordinate (0...height-1) of the pixel to return |
IllegalArgumentException | if x, y exceed the bitmap's bounds |
---|
Returns in pixels[] a copy of the data in the bitmap. Each value is a packed int representing a Color. The stride parameter allows the caller to allow for gaps in the returned pixels array between rows. For normal packed results, just pass width for the stride value.
pixels | The array to receive the bitmap's colors |
---|---|
offset | The first index to write into pixels[] |
stride | The number of entries in pixels[] to skip between rows (must be >= bitmap's width). Can be negative. |
x | The x coordinate of the first pixel to read from the bitmap |
y | The y coordinate of the first pixel to read from the bitmap |
width | The number of pixels to read from each row |
height | The number of rows to read |
IllegalArgumentException | if x, y, width, height exceed the bounds of the bitmap, or if abs(stride) < width. |
---|---|
ArrayIndexOutOfBoundsException | if the pixels array is too small to receive the specified number of pixels. |
Return the number of bytes between rows in the bitmap's pixels. Note that this refers to the pixels as stored natively by the bitmap. If you call getPixels() or setPixels(), then the pixels are uniformly treated as 32bit values, packed according to the Color class.
Returns the bitmap's width
Returns true if the bitmap's pixels support levels of alpha
Returns true if the bitmap is marked as mutable (i.e. can be drawn into)
Returns true if this bitmap has been recycled. If so, then it is an error to try to access its pixels, and the bitmap will not draw.
Free up the memory associated with this bitmap's pixels, and mark the bitmap as "dead", meaning it will throw an exception if getPixels() or setPixels() is called, and will draw nothing. This operation cannot be reversed, so it should only be called if you are sure there are no further uses for the bitmap. This is an advanced call, and normally need not be called, since the normal GC process will free up this memory when there are no more references to this bitmap.
Write the specified Color into the bitmap (assuming it is mutable) at the x,y coordinate.
x | The x coordinate of the pixel to replace (0...width-1) |
---|---|
y | The y coordinate of the pixel to replace (0...height-1) |
color | The Color to write into the bitmap |
IllegalStateException | if the bitmap is not mutable |
---|---|
IllegalArgumentException | if x, y are outside of the bitmap's bounds. |
Replace pixels in the bitmap with the colors in the array. Each element in the array is a packed int prepresenting a Color
pixels | The colors to write to the bitmap |
---|---|
offset | The index of the first color to read from pixels[] |
stride | The number of colors in pixels[] to skip between rows. Normally this value will be the same as the width of the bitmap, but it can be larger (or negative). |
x | The x coordinate of the first pixel to write to in the bitmap. |
y | The y coordinate of the first pixel to write to in the bitmap. |
width | The number of colors to copy from pixels[] per row |
height | The number of rows to write to the bitmap |
IllegalStateException | if the bitmap is not mutable |
---|---|
IllegalArgumentException | if x, y, width, height are outside of the bitmap's bounds. |
ArrayIndexOutOfBoundsException | if the pixels array is too small to receive the specified number of pixels. |
Write the bitmap and its pixels to the parcel. The bitmap can be rebuilt from the parcel by calling CREATOR.createFromParcel().
p | Parcel object to write the bitmap data into |
---|---|
flags | Additional flags about how the object should be written. May be 0 or PARCELABLE_WRITE_RETURN_VALUE. |
Is called before the object's memory is being reclaimed by the VM. This can only happen once the VM has detected, during a run of the garbage collector, that the object is no longer reachable by any thread of the running application.
The method can be used to free system resources or perform other cleanup
before the object is garbage collected. The default implementation of the
method is empty, which is also expected by the VM, but subclasses can
override finalize()
as required. Uncaught exceptions which are
thrown during the execution of this method cause it to terminate
immediately but are otherwise ignored.
Note that the VM does guarantee that finalize()
is called at most
once for any object, but it doesn't guarantee when (if at all) finalize()
will be called. For example, object B's finalize()
can delay the execution of object A's finalize()
method and
therefore it can delay the reclamation of A's memory. To be safe, use a
ReferenceQueue, because it provides more control
over the way the VM deals with references during garbage collection.
Throwable |
---|