1

这就是问题所在:我正在尝试从服务器上为我在 android 上的应用程序检索 blob 图像。第一个问题是 doInBackground 返回字符串但我想返回位图。我也不确定“bitmapImg =BitmapFactory.decodeStream(inputStream);” 行是正确的。请帮助,在此先感谢。

   class blobConnect extends AsyncTask<Boolean, String, String> {

@Override
protected String doInBackground(Boolean... params) {
String result = null;
InputStream inputStream = null;
Bitmap bitmapImg = null;
//convert response to string
try {

// http post
HttpClient httpclient = new DefaultHttpClient();
HttpGet httppost = new HttpGet("http://x.x.x.x/android_connect/img.php");
HttpResponse response = httpclient.execute(httppost);
HttpEntity httpEntity = response.getEntity();
inputStream= httpEntity.getContent();
if (response.getStatusLine().getStatusCode() != 200) {
Log.d("MyApp", "Server encountered an error");
}
bitmapImg =BitmapFactory.decodeStream(inputStream);
Log.d("test", bitmapImg);
} catch (Exception e) {
Log.e("log_tag", "Error converting result " + e.toString());
}
return bitmapImg;
}
}
}
4

0 回答 0