I was looking for a way how to extract the pixel value (RGB) of a selected (x,y) from my screen
(My display countains many images, not only the background)
thanks
I was looking for a way how to extract the pixel value (RGB) of a selected (x,y) from my screen
(My display countains many images, not only the background)
thanks
First of all you need the root container of your activity. Suppose xml of your activity looks like this:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/container"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- All your stuff-->
</RelativeLayout>
Then in the activity find the root and using jkhouw1
method get Bitmap
which has method getPixel
:
@Override
protected void onCreate(Bundle savedInstanceState) {
//...
View container = findViewById(R.id.container);
Bitmap bitmap = loadBitmapFromView(container);
int pixel = bitmap.getPixel(100, 100);
int r = Color.red(pixel);
int b = Color.blue(pixel);
int g = Color.green(pixel);
}
public static Bitmap loadBitmapFromView(View v) {
Bitmap b = Bitmap.createBitmap( v.getLayoutParams().width, v.getLayoutParams().height, Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(b);
v.layout(0, 0, v.getLayoutParams().width, v.getLayoutParams().height);
v.draw(c);
return b;
}