当前位置: 代码迷 >> Android >> 怎么将bitmap的RGB值传给二维数组
  详细解决方案

怎么将bitmap的RGB值传给二维数组

热度:52   发布时间:2016-05-01 21:53:15.0
如何将bitmap的RGB值传给二维数组
请问各位高手,如何将如何将bitmap的R/G/B值传给二维数组?

大致过程应该是
int[][] R=new int [height][with];
int[][] G=new int [height][with];
int[][] B=new int [height][with];
for(i=0,i<height,i++)
{
for(j=0,j<with,j++)
{
R[i][j]=????; 
}
}

没专们学过android,所以不知怎么写,希望有人能帮下 (o_0)

------解决方案--------------------
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
------解决方案--------------------
R[i][j] = Color.red(bitmap.getPixel(j, i));
G[i][j] = Color.green(bitmap.getPixel(j, i));
B[i][j] = Color.blue(bitmap.getPixel(j, i));

bitmap.getPixel(j,i)获取bitmap中位置为(j,i)的颜色值;
Color.red(int color)从颜色值color中获取红色的值;
  相关解决方案