0

I have a RGB Wheel Here PNG image on Android Activity and a color like #6DFFE0.

I want to find the color's X, Y coordinates (location) within RGB wheel so that I can move my indicator there dynamically in Android. Code should be in Android/Java only.

mwilson
  • 12,295
  • 7
  • 55
  • 95

1 Answers1

1

You can loop all pixels and get the pixels which are matching the color that you given

    ArrayList<String> pixels_matching_color = new ArrayList<>();
    int color_to_find = Color.RED; //#FF0000 
    ImageView imageView = new ImageView(this);
    Bitmap bitmap = ((BitmapDrawable)imageView.getDrawable()).getBitmap();
    int total_width = bitmap.getWidth();
    int total_height = bitmap.getHeight();
    for (int y = 0; y < total_height; y++) {
        for (int x = 0; x < total_width; x++) {
            int pixel = bitmap.getPixel(x,y);
            //Reading colors
            int redValue = Color.red(pixel);
            int blueValue = Color.blue(pixel);
            int greenValue = Color.green(pixel);

            //finally creating the color for pixel
            int pixel_color = Color.rgb(redValue, blueValue, greenValue);
            if (pixel_color == color_to_find){
                pixels_matching_color.add(String.format("%s,%s",x,y));
            }
        }
    }
    //the array will contans the pixels that are matching the color you given
    System.out.println(pixels_matching_color);
Jefriiyer S
  • 558
  • 1
  • 5
  • 13
  • Hello jefriiyer i want to generate X Y Points from color. You are saying reverse. Like i will pass int color to some function and it will find that color within the image or whole screen and returns its XY cordinates. – Dinesh Raturi May 03 '18 at 12:07