0
我想要在觸摸點上方的放大氣球中顯示觸摸圖像時選擇的顏色。類似於使用分項疊加在地圖中顯示我的當前位置。這怎麼能實現?顯示從覆蓋圖像觸摸事件中選擇的顏色
我想要在觸摸點上方的放大氣球中顯示觸摸圖像時選擇的顏色。類似於使用分項疊加在地圖中顯示我的當前位置。這怎麼能實現?顯示從覆蓋圖像觸摸事件中選擇的顏色
int color = bitmap.getPixel((int)event.getX(),(int)event.getX());
RGB.setText(" R:"+Color.red(color)+" G:"+Color.green(color)+" B:"+Color.blue(color));
這是一個很好的問題和以前的答案需要詳細說明一下這個代碼片段的方式:
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;
}
});