Android canvas = Canvas(bitmap)抛错:java.lang.IllegalStateException: Immutable bitmap passed to Canvas

Android canvas = Canvas(bitmap)抛错:java.lang.IllegalStateException: Immutable bitmap passed to Canvas constructor at android.graphics.Canvas.<init>(Canvas.java:114),Kotlin

java.lang.IllegalStateException: Immutable bitmap passed to Canvas constructor
                                                                                                        at android.graphics.Canvas.<init>(Canvas.java:114)

抛错代码:

        val bitmap = BitmapFactory.decodeResource(resources, R.mipmap.pic)
        val canvas = Canvas(bitmap)

解决:

        val bitmap = BitmapFactory.decodeResource(resources, R.mipmap.pic).copy(Bitmap.Config.ARGB_8888, true)
        val canvas = Canvas(bitmap)

Android画布Canvas绘图scale & translate,Kotlin-CSDN博客文章浏览阅读440次,点赞4次,收藏11次。文章浏览阅读9.6k次。文章浏览阅读1.8k次。/*Java代码 将Drawable转化为Bitmap */ Bitmap drawableToBitmap(Drawable drawable) { int width = drawable.getIntrinsicWidth();Android Material Design :LinearLayoutCompat添加分割线divider_linearlayout 分割线-CSDN博客。https://blog.csdn.net/zhangphil/article/details/134930229

猜你喜欢

转载自blog.csdn.net/zhangphil/article/details/135113056
今日推荐