Android从Drawable资源Id直接生成Bitmap,Kotlin
val t1 = System.currentTimeMillis()val bmp = getBmpFromDrawId(this, R.mipmap.ic_launcher_round)Log.d("fly", "1 ${bmp?.byteCount} h=${bmp?.height} w=${bmp?.width} cost time=${System.currentTimeMillis() - t1}")val t2 = System.currentTimeMillis()val scaleBmp = Bitmap.createScaledBitmap(bmp!!, 800, 800, true)Log.d("fly", "2 ${scaleBmp.byteCount} h=${scaleBmp.height} w=${scaleBmp.width} cost time=${System.currentTimeMillis() - t2}")
private fun getBmpFromDrawId(context: Context, drawId: Int): Bitmap? {val drawable = ContextCompat.getDrawable(context, drawId)val bitmap = drawable?.let {Bitmap.createBitmap(it.intrinsicWidth,it.intrinsicHeight,Bitmap.Config.ARGB_8888)}val canvas = bitmap?.let { Canvas(it) }if (canvas != null) {drawable.setBounds(0, 0, canvas.width, canvas.height)drawable.draw(canvas)}return bitmap}
Android Drawable转BitmapDrawable再提取Bitmap,Kotlin_android drawable to bitmap-CSDN博客文章浏览阅读864次。*Java代码 将Drawable转化为Bitmap */ Bitmap drawableToBitmap(Drawable drawable) { int width = drawable.getIntrinsicWidth();Android传递Bitmap的两种简单方式及其缺陷_android上传bitmap_zhangphil的博客-CSDN博客。_android drawable to bitmaphttps://blog.csdn.net/zhangphil/article/details/132351440
Android Drawable 转化成 Bitmap_android drawable 转为 bitmap-CSDN博客文章浏览阅读2k次。/*Java代码 将Drawable转化为Bitmap */ Bitmap drawableToBitmap(Drawable drawable) { int width = drawable.getIntrinsicWidth(); int height = drawable.getIntrinsicHeight(); Bitmap bitmap_android drawable 转为 bitmaphttps://blog.csdn.net/zhangphil/article/details/43767535