如何解码在Base64中编码的png图像并在ImageView上查看?

时间:2022-12-02 21:38:24

My android device requests to the server a png image. The server encodes the image in Base64 and sends it to my device. After that, I decode the Base64 string into a byte array and use BitmapFactory.decodeByteArray() to make a Bitmap image of it. I can't see the image when I add it in an ImageView.

我的android设备向服务器请求一个png图像。服务器在Base64中对映像进行编码并将其发送到我的设备。之后,我将Base64字符串解码为字节数组,并使用BitmapFactory.decodeByteArray()来制作它的Bitmap图像。当我在ImageView中添加图像时,我看不到图像。

See below for the code:

请参阅下面的代码:

JSONObject params = resultObject.getJSONObject("params");
byte[] decodedImageInBytes = Base64.decode(params.getString("image_one"), Base64.DEFAULT);

Bitmap myImage = BitmapFactory.decodeByteArray(decodedImageInBytes, 0, decodedImageInBytes.length);
ImageView imageViewOne = (ImageView) findViewById(R.id.imageViewOne);
imageViewOne.setImageBitmap(myImage);

Edit:

It seems that my code is okay, I have some problems with the server. Thanks everyone!

似乎我的代码没问题,我在服务器上遇到了一些问题。感谢大家!

1 个解决方案

#1


3  

I have decoded your string for you. It is not bitmap data.

我已经为你解码了你的字符串。它不是位图数据。

Unknown error type: [2] include(/home/hospitalit/domains/hospitalitymanager.nl/public_html/demo/application//controllers/global/statistic_images/reservation_guest_rank) [<a href='function.include'>function.include</a>]: failed to open stream: No such file or directory<br />
on line 45 in file /home/hospitalit/domains/hospitalitymanager.nl/public_html/demo/application/controllers/api/statistics/index.phpUnknown error type: [2] include() [<a href='function.include'>function.include</a>]: Failed opening '/home/hospitalit/domains/hospitalitymanager.nl/public_html/demo/application//controllers/global/statistic_images/reservation_guest_rank' for inclusion (include_path='.:/usr/local/lib/php')<br />
on line 45 in file /home/hospitalit/domains/hospitalitymanager.nl/public_html/demo/application/controllers/api/statistics/index.php

#1


3  

I have decoded your string for you. It is not bitmap data.

我已经为你解码了你的字符串。它不是位图数据。

Unknown error type: [2] include(/home/hospitalit/domains/hospitalitymanager.nl/public_html/demo/application//controllers/global/statistic_images/reservation_guest_rank) [<a href='function.include'>function.include</a>]: failed to open stream: No such file or directory<br />
on line 45 in file /home/hospitalit/domains/hospitalitymanager.nl/public_html/demo/application/controllers/api/statistics/index.phpUnknown error type: [2] include() [<a href='function.include'>function.include</a>]: Failed opening '/home/hospitalit/domains/hospitalitymanager.nl/public_html/demo/application//controllers/global/statistic_images/reservation_guest_rank' for inclusion (include_path='.:/usr/local/lib/php')<br />
on line 45 in file /home/hospitalit/domains/hospitalitymanager.nl/public_html/demo/application/controllers/api/statistics/index.php