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....

4
  • friends i need your help.......help me Commented Mar 30, 2015 at 9:37
  • Use this : stackoverflow.com/a/29341566/4693713 Commented Mar 30, 2015 at 9:37
  • byte[] decodedString = Base64.decode(encodedImage, Base64.DEFAULT); Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length); Commented Mar 30, 2015 at 9:42
  • Hey @signare that is not working.... Commented Mar 30, 2015 at 11:43

1 Answer 1

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);
Sign up to request clarification or add additional context in comments.

1 Comment

Hey Zinal Do you use Base64 Util Class or own developed class

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.