问题
How to convert imageview to bytearray kotlin android
In java
Bitmap bitmap = ((BitmapDrawable)image.getDrawable()).getBitmap();
ByteArrayOutputStream stream=new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 90, stream);
byte[] image=stream.toByteArray();
return image
回答1:
Here it is use java to kotlin converter.
val bitmap = (image.getDrawable() as BitmapDrawable).getBitmap()
val stream = ByteArrayOutputStream()
bitmap.compress(Bitmap.CompressFormat.PNG, 90, stream)
val image = stream.toByteArray()
回答2:
This may help you,
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()
}
来源:https://stackoverflow.com/questions/46666308/how-to-convert-imageview-to-bytearray-in-kotlin