如何将imageview转换为kotlin中的bytearray
如何将imageview转换为bytearray kotlin android
在java中
Bitmap bitmap = ((BitmapDrawable)image.getDrawable()).getBitmap(); ByteArrayOutputStream stream=new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.PNG, 90, stream); byte[] image=stream.toByteArray(); return image
这里使用java来转换kotlin。
val bitmap = (image.getDrawable() as BitmapDrawable).getBitmap() val stream = ByteArrayOutputStream() bitmap.compress(Bitmap.CompressFormat.PNG, 90, stream) val image = stream.toByteArray()
这可能会帮助你,
private fun imageToBitmap(image: ImageView): ByteArray { val bitmap = (image.drawable as BitmapDrawable).bitmap val stream = ByteArrayOutputStream() bitmap.compress(Bitmap.CompressFormat.PNG, 90, stream) return stream.toByteArray() }
- 我正在尝试从SD卡播放音乐
- 如何使用Fragment的数据绑定
- 在Android Studio中为Kotlin模块配置“build.gradle”
- 使用kotlin的自定义风格中的ClassNotFoundException
- EmojiCompat生成的ID“android:id / inputExtractEditText”
- 我想使用Kotlin在Android中显示DialogFragment
- Asp.net mvc WCF服务现在
- Recycler中的checkbox勾选为true时,查看项目被immedietaly选中为false
- Kotlin Android-如何实现CheckBox.OnCheckedChangeListener?