androidimageviewkotlin

How to convert imageview to bytearray in kotlin


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

Solution

  • 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()