I am trying to get the color value of a particular pixel in a Bitmap object.
I have the following function in my MainActivity.java
:
@RequiresApi(api = Build.VERSION_CODES.Q)
private boolean isCenterWhitePixel(Bitmap bitmap) {
Color color = bitmap.getColor(150, 150);
int[] rgbValues = { (int) color.red(), (int) color.green(), (int) color.blue()};
if (rgbValues[0] == 255 && rgbValues[1] == 255 && rgbValues[2] == 255) {
return true;
}
else {
return false;
}
}
Note: the line @RequiresApi(api = Build.VERSION_CODES.Q)
was added to the top because on the line Color color = bitmap.getColor(150, 150);
android studios' tooltip complained with the following:
Call requires API level Q (current min is 23): android.graphics.Bitmap#getColor
So I followed what android studio suggested as a solution and added that @RequiresAPI
line.
As a result I got the following error:
java.lang.NoSuchMethodError: No virtual method getColor(II)Landroid/graphics/Color; in class Landroid/graphics/Bitmap; or its super classes (declaration of 'android.graphics.Bitmap' appears in /system/framework/framework.jar)
Any way to get the Bitmap.getColor
function to work?