Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I decode a png image encoded in Base64 and see it on an ImageView?

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.

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!

like image 643
Aerial Avatar asked Oct 24 '22 03:10

Aerial


1 Answers

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
like image 137
Renard Avatar answered Oct 27 '22 11:10

Renard