如何从ImageView获取像素值
How to get pixel value from ImageView
点击 button
后,是否可以从 ImageView
获取像素值?我已经进行了挖掘和搜索,但大多数解决方案都使用 imageView.setOnTouchListener(new OnTouchListener()
方法。
但我真正想要的是在点击 button
之后获取像素值。有什么推荐吗?
你能试试这个吗?
Bitmap bitmap = ((BitmapDrawable)imageView.getDrawable()).getBitmap();
int pixel = bitmap .getPixel(x,y);
尝试 -
private Bitmap bmp;
private int[][] rgbValues;
bmp = BitmapFactory.decodeResource(getResources(), R.drawable.four_colors);
//define the array size
rgbValues = new int[bmp.getWidth()][bmp.getHeight()];
for(int i=0; i < bmp.getWidth(); i++)
{
for(int j=0; j < bmp.getHeight(); j++)
{
rgbValues[i][j] = bmp.getPixel(i, j);
}
}
如需完整代码,请转到此 link。
点击 button
后,是否可以从 ImageView
获取像素值?我已经进行了挖掘和搜索,但大多数解决方案都使用 imageView.setOnTouchListener(new OnTouchListener()
方法。
但我真正想要的是在点击 button
之后获取像素值。有什么推荐吗?
你能试试这个吗?
Bitmap bitmap = ((BitmapDrawable)imageView.getDrawable()).getBitmap();
int pixel = bitmap .getPixel(x,y);
尝试 -
private Bitmap bmp;
private int[][] rgbValues;
bmp = BitmapFactory.decodeResource(getResources(), R.drawable.four_colors);
//define the array size
rgbValues = new int[bmp.getWidth()][bmp.getHeight()];
for(int i=0; i < bmp.getWidth(); i++)
{
for(int j=0; j < bmp.getHeight(); j++)
{
rgbValues[i][j] = bmp.getPixel(i, j);
}
}
如需完整代码,请转到此 link。