更改android中触摸事件触摸像素的位图颜色

时间:2014-10-18 19:00:22

标签: android graphics pixels bitmapimage bitmapfactory

我正在尝试开发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;
}

请帮助

0 个答案:

没有答案