首页 > 解决方案 > java.lang.IllegalArgumentException:无法创建没有颜色空间的位图

问题描述

渲染自定义视图时出现上述错误,错误发生在这一行val b = Bitmap.createBitmap(bmp,0,bmp.height-height,width,height),位图的宽度和高度bmt大于我要剪辑的宽度和高度。谁有这个问题的想法?先谢谢啦!!!

 rootView.getViewTreeObserver().addOnPreDrawListener(object : ViewTreeObserver.OnPreDrawListener {
           override fun onPreDraw(): Boolean {
               rootView.getViewTreeObserver().removeOnPreDrawListener(this)
               rootView.buildDrawingCache()
                val bmp: Bitmap = rootView.getDrawingCache()
               Timber.d(" test ${bmp.width} ${bmp.height}  $x $y   $width $height")
               val b = Bitmap.createBitmap(bmp,0,bmp.height-height,width,height)
               background = BitmapDrawable(context.resources, b)
                return true
            }
        })

标签: android

解决方案


推荐阅读