public void getPixels (int[] pixels, int offset, int stride, int x, int y, int width, int height)
Since:
API Level 1
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.
Parameters
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
IllegalArgumentException if x, y, width, height exceed the bounds of the bitmap, or if abs(stride) < width.
ArrayIndexOutOfBoundsException
例:
mBarPixels = new int[mWidth * mHeight];
mBarBitmap.getPixels(mBarPixels, 0, mWidth, i, 0, mWidth, mHeight);
//从(i,0)点 开始截取像素,放入 mBarPixels 数组中。
canvas.drawBitmap(mBarPixels, 0, mWidth, 0, 0, mWidth, mHeight, true, null);
//使用像素
public void drawBitmap (int[] colors, int offset, int stride, float x, float y, int width, int height, boolean hasAlpha, Paint paint)
colors | Array of colors representing the pixels of the bitmap |
---|---|
offset | Offset into the array of colors for the first pixel |
stride | The number of colors in the array between rows (must be >= width or <= -width). |
x | The X coordinate for where to draw the bitmap |
y | The Y coordinate for where to draw the bitmap |
width | The width of the bitmap |
height | The height of the bitmap |
hasAlpha | True if the alpha channel of the colors contains valid values. If false, the alpha byte is ignored (assumed to be 0xFF for every pixel). |
paint | May be null. The paint used to draw the bitmap |