基本上有以下两个障碍:
- 我想在单击光标的坐标处获取图像的背景颜色。代码第一次获取颜色和坐标。但是当我再次单击时,会发生错误。
- 我想以十六进制而不是 RGB 整数值获取图像的颜色,然后在找到颜色的特定区域中用我的颜色更改该特定颜色。
这是代码:
private ImageView mImageView;
private Button button;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.vp_view_img);
if(getIntent().hasExtra("BitmapImage"))
{
final Bitmap bitmap = (Bitmap) getIntent().getParcelableExtra("BitmapImage");
mImageView = (ImageView) findViewById(R.id.canvas_image);
mImageView.setImageBitmap(bitmap);
mImageView.setOnTouchListener(new ImageView.OnTouchListener()
{
@Override
public boolean onTouch(View v, MotionEvent event)
{
int x = (int)event.getX();
int y = (int)event.getY();
/*Toast.makeText(getBaseContext(), "Touch coordinates : "
+ String.valueOf(event.getX()) + "x"
+ String.valueOf(event.getY()),
Toast.LENGTH_SHORT).show();*/
ImageView imageView = (ImageView) v;
Bitmap bitmap = ((BitmapDrawable)imageView.getDrawable()).getBitmap();
int pixel = bitmap.getPixel(x,y);
int redValue = Color.red(pixel);
int blueValue = Color.blue(pixel);
int greenValue = Color.green(pixel);
Toast.makeText(getBaseContext(), "Color Code :"+
redValue+blueValue+greenValue,Toast.LENGTH_SHORT).show();
return true;
}
});
}
else
{
Toast.makeText(getBaseContext(),
"No Image Found",
Toast.LENGTH_LONG).show();
}
}