Search code examples
androidcolorsandroid-emulatorpixel

get pixel color in Android emulator at x,y position


I have the x,y position on the Android emulator screen. Is there a way to find the pixel color at this specific x,y in the emulator screen?


Solution

  • Yes you can, this is the code I use the get the RGB value of a specific pixel in any view.

    view.setDrawingCacheEnabled(true);
    view.buildDrawingCache();
    Bitmap bitmap = view.getDrawingCache();
    
    int pixel = bitmap.getPixel(x,y);
    
    int red = Color.red(pixel);
    int green = Color.green(pixel);
    int blue = Color.blue(pixel);
    
    view.setDrawingCacheEnabled(false);
    

    The int values returned are your standard 0 - 255. You can modify this code and get a color from anywhere, providing you can turn it into a bitmap. And you can use the Color API to get an actual RGB value like this:

    int rgb = Color.rgb(red, blue, green);