2010-11-17 24 views

回答

1
int color = bitmap.getPixel((int)event.getX(),(int)event.getX()); 

        RGB.setText(" R:"+Color.red(color)+" G:"+Color.green(color)+" B:"+Color.blue(color)); 
1

這是一個很好的問題和以前的答案需要詳細說明一下這個代碼片段的方式:

imageView1 = (ImageView)findViewById(R.id.imageView1); 
    imageView1.setOnTouchListener(new View.OnTouchListener() { 
     public boolean onTouch(View v, MotionEvent event) { 
      if (event.getAction() == MotionEvent.ACTION_DOWN){ 
       int positionX = (int)event.getX(); 
       int positionY = (int)event.getY();    

       Log.i("ON TOUCH COORDINATES","x: "+positionX + " y: " + positionY); 
       BitmapDrawable bd = (BitmapDrawable)imageView1.getDrawable(); 
       Bitmap bitmap = bd.getBitmap(); 
       int color_selected = bitmap.getPixel(positionX, positionY); 
       Log.i("COLOR SELECTED"," "+color_selected); 
      } 
      return true; 
     } 
    });