Android ByteBuffer Bitmap byte[] convert,Kotlin

Android use ByteBuffer convert Bitmap to byte[],Kotlin

1、

Bitmap to byte[] array:

    fun Bitmap.toByte(bmp: Bitmap): ByteArray {
        val baos = ByteArrayOutputStream()
        bmp.compress(Bitmap.CompressFormat.PNG, 100, baos)
        return baos.toByteArray()
    }

2、

byte[] to Bitmap:

fun toBitmap(bytes: ByteArray): Bitmap {
        return BitmapFactory.decodeByteArray(bytes, 0, bytes.size)
    }

Android Drawable 转化成 Bitmap_zhangphil的博客-CSDN博客/*Java代码 将Drawable转化为Bitmap */ Bitmap drawableToBitmap(Drawable drawable) { int width = drawable.getIntrinsicWidth(); int height = drawable.getIntrinsicHeight(); Bitmap bitmaphttps://blog.csdn.net/zhangphil/article/details/43767535Android Drawable转BitmapDrawable再提取Bitmap,Kotlin-CSDN博客*Java代码 将Drawable转化为Bitmap */ Bitmap drawableToBitmap(Drawable drawable) { int width = drawable.getIntrinsicWidth();Android传递Bitmap的两种简单方式及其缺陷_android上传bitmap_zhangphil的博客-CSDN博客。https://blog.csdn.net/zhangphil/article/details/132351440

你可能感兴趣的:(Android,kotlin,android,kotlin)