我正在尝试开发app,当用户触摸黑色时,它会将触摸像素的颜色更改为黄色 但它没有工作它不会改变颜色 公共类MainActivity扩展ActionBarActivity实现OnTouchListener {
ImageView iv;
Bitmap bitmap,b;
Bitmap mutableBitmap ,mb;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
iv=(ImageView) findViewById(R.id.imageView1);
bitmap = ((BitmapDrawable)iv.getDrawable()).getBitmap();
mb=bitmap.copy(Bitmap.Config.ARGB_8888,true);
iv.setImageBitmap(mb);
change();
iv.setOnTouchListener(MainActivity.this);
}
public boolean onTouch(View v, MotionEvent event){
int x = (int)event.getX();
int y = (int)event.getY();
int width = mb.getWidth();
int height =mb.getHeight();
int[] pixels = new int[width * height];
mb.getPixels(pixels, 0, width, 0, 0, width, height);
for(int i = 0; i < pixels.length; ++i) {
if(i==x*y){
int redValue = Color.red(pixels[i]);
int blueValue = Color.blue(pixels[i]);
int greenValue = Color.green(pixels[i]);
if (redValue ==0 && blueValue==0 && greenValue==0)
{ pixels[i]= 0xFFFFFF00;
Log.v(" action down ", " color change "); }
}
}
mb = Bitmap.createBitmap(pixels, mb.getWidth(), mb.getHeight(), Bitmap.Config.ARGB_8888);
iv.setImageBitmap(mb);
//mb=result.copy(Bitmap.Config.ARGB_8888,true);
return false;
}
请帮助