无法使用位图imageView Java创建图像
我有一个代码,可以通过python蓝牙接收字节。 发送的数据是颜色橙色BGR = [0,106,254]的10x10 JPG的数组。 我试图使用此代码在Android Studio中显示图像:
''''''
private void readImage(byte[] readBuf) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
//BufferedInputStream = readBuf;
ImageView imageView = (ImageView) findViewById(R.id.PiCam);
String s = new String(readBuf, StandardCharsets.UTF_8);
byte[] x = Base64.decode(s, Base64.DEFAULT); //convert from base64 to byte array
Bitmap bitmap = BitmapFactory.decodeByteArray(x, 0, x.length);
imageView.setImageBitmap(bitmap);
System.out.println(x);
}
}
''''''
''''''''''''''''''''''''''' 。
我认为以下消息意味着位图无法通过ImageView显示。 当我打印位图时,无法创建带有消息“未完成”的图像解码器
,它给出了“ null”,所以解码失败了?
我的目标是发送图像,解码并显示它。 让我知道我是否可以提供更多细节。
I have a piece of code that receives Bytearrays via bluetooth with Python.
The data sent is an array of a 10x10 jpg of the color orange BGR=[0,106,254].
Im trying to display the image in Android Studio using this code:
'''
private void readImage(byte[] readBuf) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
//BufferedInputStream = readBuf;
ImageView imageView = (ImageView) findViewById(R.id.PiCam);
String s = new String(readBuf, StandardCharsets.UTF_8);
byte[] x = Base64.decode(s, Base64.DEFAULT); //convert from base64 to byte array
Bitmap bitmap = BitmapFactory.decodeByteArray(x, 0, x.length);
imageView.setImageBitmap(bitmap);
System.out.println(x);
}
}
'''
System.out.println(x) gives me [B@31b9d31 and [B@18d0c16, so these are the byte arrays that are decoded by decodeByteArray.
I think that the following message means that the bitmap can't be displayed by ImageView.
Failed to create image decoder with message 'unimplemented'
When I i print bitmap, it gives 'null', so perhaps the decoding failed?
My goal is to send an image, to decode it and to display it.
Let me know if I could provide any more details.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论