我有一个渐变。我想在触摸时在像素上取颜色。我正在尝试从视图和以后的位图中获取可绘制。但它是投掷
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)
任何帮助的方式。谢谢
您可以创建GradientDrawable
的位图,然后查找特定像素的颜色。
从这个答案:
// 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