我正在开发一个应用程序,它从 php 服务器下载图像并在图像视图中显示图像..但是当我从 php 页面接收图像时
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);
}
它给了我这样的 json 响应
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
我正在将这个图像字符串解码为位图,如下所示......
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();
}
我正在使用这个 bm 到 onotherclass ,将 bmp 设置为 imageview
ivProperty.setImageBitmap(bmp);
但它没有显示任何内容......我的异步任务活动尚未完成并且它继续运行......
我的问题是如何将 bmp 显示到 imageview 以及为什么我的 asyncktask 没有完成......提前谢谢......