0

I am building an app with Kotlin frontend/Python backend and I want to display an image that is in bytecode. My python script uses BytesIO() (https://docs.python.org/3/library/io.html#io.BytesIO) to return image's bytecode (ex. <_io.BytesIO object at 0x6f2496j0>) and I want to use kotlin to display its image.

Is this even possible? If so, how can I assign image values to imageView id for example? Sample code of it will be much appreciated.

Thank you.

4
  • Does this answer your question? Android: how to convert byte array to Bitmap? Commented May 27, 2020 at 15:37
  • @LalitFauzdar I don't think I can solve it with the post alone. My guess is to use BitmapFactory.decodeStream to create a Bitmap and assign that value into a corresponding ImageView id. Is this correct? Commented May 27, 2020 at 16:24
  • @小尾穣 if you know how to convert a byte array into Bitmap then what challenge you are facing to set that bitmap into Imageview. Please describe your problem more specific Commented May 27, 2020 at 16:46
  • I'm still uncertain about converting byte into Bitmap since i never this tried before. Also i'm not familiar with assigning values to Imageview id dynamically so this is also new to me. Thats why I want to 1. know that my approach is appropriate and 2. have a sample kotlin syntax to achieve my goal. Commented May 27, 2020 at 16:54

1 Answer 1

0

//optional code

  val bmp = BitmapFactory.decodeResource(resources, R.drawable.person)
val stream = ByteArrayOutputStream()
bmp.compress(Bitmap.CompressFormat.PNG, 100, stream)

// assign bytes getting from seerver to byteArray

val byteArray: ByteArray = stream.toByteArray()
val bitmap = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.size)
imageView.setImageBitmap(bitmap)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.