无法使用位图imageView Java创建图像

发布于 2025-02-01 16:41:16 字数 857 浏览 3 评论 0原文

我有一个代码,可以通过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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文