android - 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
}
})
解决方案
推荐阅读
- listview - 在 Flutter 中清除 ListView
- python - 在 ipython 实例之间共享命名空间/环境
- firebase - React Native Firebase 动态链接传递数据
- python - 在 matplotlib 中找不到 SyntaxError 的原因
- json - Flutter:如何将 Json 文件下载到本地然后访问它
- design-patterns - 契约模式匹配
- javascript - 有没有办法修复网络 204 ReactJS 中的 Restful API 没有内容
- android - Dart flutter if-else body 属性
- html - 如何在css中自动控制链接内图像的高度
- sparql - 如何在 Wikidata SPARQL 查询中获得正常排名的“instance of”(wdt:P31) 条目?