android php mysql json 查询,使用json从PHP-MySql服务器到Android获取图像

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

解决方案

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值