Reputation: 63
I have a gradient in view. I want to take a color on pixel on touch.I'm trying to get drawable from view and later bitmap. But it's throw
java.lang.ClassCastException: android.graphics.drawable.GradientDrawable cannot be cast to android.graphics.drawable.BitmapDrawable
at com.mti.videodiary.activity.SplashActivity.addColorGradient(SplashActivity.java:431)
Any ways to help. Thanks
Upvotes: 0
Views: 1002
Reputation: 3620
You can create a bitmap of the GradientDrawable
and then look for the colour of a specific pixel.
From this answer:
// create bitmap based on width and height of the gradient drawable
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
gd.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
gd.draw(canvas);
// bitmap now contains a bitmap of the gradient drawable
Upvotes: 2