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

时间:2012-04-06 20:14:05

标签: java android image png bytearray

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

请参阅下面的代码:

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);

修改

似乎我的代码没问题,我的服务器有些问题。谢谢大家!

1 个答案:

答案 0 :(得分:3)

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

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