欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 新闻 > 会展 > Android从Drawable资源Id直接生成Bitmap,Kotlin

Android从Drawable资源Id直接生成Bitmap,Kotlin

2024/11/20 3:12:14 来源:https://blog.csdn.net/zhangphil/article/details/143805009  浏览:    关键词:Android从Drawable资源Id直接生成Bitmap,Kotlin

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

 

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com