Advertisement
Guest User

Untitled

a guest
Jul 24th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. imageView=(ImageView)findViewById(R.id.imageView);
  2.  
  3. final Bitmap bitmap = ((BitmapDrawable)
  4. imageView.getDrawable()).getBitmap();
  5.  
  6. imageView.setOnTouchListener(new View.OnTouchListener() {
  7.  
  8. @Override
  9. public boolean onTouch(View v,MotionEvent event) {
  10.  
  11. int x= (int)event.getX();
  12. int y= (int)event.getY();
  13. int pixel = bitmap.getPixel(x, y);
  14.  
  15. int redValue = Color.red(pixel);
  16. int greenValue = Color.green(pixel);
  17. int blueValue = Color.blue(pixel);
  18.  
  19. // Toast.makeText(MainActivity.this,String.format("#%02x%02x%02x", redValue,
  20. greenValue, blueValue), Toast.LENGTH_LONG).show();
  21.  
  22. Toast.makeText(MainActivity.this, "R= " + redValue + "G= " + greenValue +
  23. "B= " + blueValue, Toast.LENGTH_LONG).show();
  24. // Toast.makeText(MainActivity.this,""+x+"tY "+y,Toast.LENGTH_LONG).show();
  25.  
  26. return false;
  27. }
  28. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement