How to convert a 2D ByteArray to bitmap? #20256
Unanswered
vincentme
asked this question in
Mobile Q&A
Replies: 1 comment
-
If you pull it out as a |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
This should be a dumb question. Because I am a pure novince to android and kotlin, but now I need to create a demo to run a onnx model. It works on the desktop python api.
I followed onnxruntime-inference-examples-main/mobile/examples/super_resolution exactly. But the output of my model is a 2D ByteArray (unit8) image. So how to convert it to a bitmap for display?
This does not work, since the result of super_resolution was encoded, by mine is not.
val rawOutput = (output?.get(0)?.value) as ByteArray
val outputImageBitmap = byteArrayToBitmap(rawOutput)
private fun byteArrayToBitmap(data: ByteArray): Bitmap {
return BitmapFactory.decodeByteArray(data, 0, data.size)
}
now the error is
java.lang.ClassCastException: byte[][] cannot be cast to byte[]
Beta Was this translation helpful? Give feedback.
All reactions