我有一个渐变视角。我想在触摸上的像素上采用一种颜色。我试图从视图和后来的位图中获取可绘制的颜色。但它是扔了
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)
任何帮助方式。感谢
答案 0 :(得分:2)
您可以创建GradientDrawable
的位图,然后查找特定像素的颜色。
来自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