5

我的 android 设备向服务器请求 png 图像。服务器将图像编码为 Base64 并将其发送到我的设备。之后,我将 Base64 字符串解码为字节数组,并使用 BitmapFactory.decodeByteArray() 制作它的位图图像。当我将图像添加到 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);

编辑:

看来我的代码没问题,我的服务器有一些问题。谢谢大家!

4

1 回答 1

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
于 2012-04-06T20:30:40.653 回答