1

i am devloping an application which download image from php-server and display image in image view ..but when i receive image from php page

if (!empty($result)) {
    if (mysql_num_rows($result) > 0) {

        $result = mysql_fetch_array($result);

        $user = array();
        $user["image"] = base64_encode($result["image"]);
        $response["success"] = 1;
       $response["image_table"] = array();

        array_push($response["image_table"], $user);
        echo json_encode($response);
    } else {
        $response["success"] = 0;
        $response["message"] = "No Image found";
        echo json_encode($response);
    }

it gives me json response like this

03-30 04:43:44.013: D/Image:(2770): {"success":1,"image_table":   [{"image":"\/9j\/4VeRRXhpZgAASUkqAAgAAAAMAAABBAABAAAA..........
03-30 04:43:44.253: D/skia(2770): --- decoder->decode returned false

i m decoding this image string to bitmap like this....

json= jsonParser.makeHttpRequest(url_img_address, "GET", params);

        Log.d("Image: ", json.toString());

        try {
            int success = json.getInt(TAG_SUCCESS);

            if (success == 1) {
                address = json.getJSONArray(TAG_IMAGE_TABLE);
                for (int i = 0; i < address.length(); i++) {
                    JSONObject c = address.getJSONObject(i);
                    image = c.getString(TAG_IMAGE);
                     byte[] dwimage = Base64.decode(image.getBytes());
                      System.out.println(dwimage);
                      bmp = BitmapFactory.decodeByteArray(dwimage, 0, dwimage.length);
                } 
            } else {

            }
        } catch (JSONException | IOException e) {
            e.printStackTrace();
        }

and i m using this bm to onotherclass which set bmp to imageview

   ivProperty.setImageBitmap(bmp);

but it dosent display anything......my asynck task activity is not finished and it continuesly running... my question is that how to display bmp to imageview and why my asyncktask is not finished........thx in advance....

Tufan
  • 2,789
  • 4
  • 34
  • 52

1 Answers1

4

You need to use binary decoding using base64 decode, and you will get image as bitmap..

byte[] decodedString = Base64.decode(encodedImage, Base64.DEFAULT);
Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);
Aditi Parikh
  • 1,522
  • 3
  • 13
  • 34
Rohit Suthar
  • 2,635
  • 1
  • 22
  • 27