从Web服务中的Android 3.0及以上获得从InputStream中加载问题的ImageView [英] Issue loading ImageView from InputStream obtained from web service in Android 3.0 and above
问题描述
我的应用程序能够显示从Web服务获得InputStream中的图像数据的图像preVIEW。 InputStream为德coded到位图来显示在ImageView的。这整个流程采用的是Android 2.2和2.3做工精细,而它不与Android 3.0和4.0运行。位图德codeD在后一种情况下,而它在2.X精细空。
My app has to display an image preview from the image data obtained as InputStream from a web service. InputStream is decoded to Bitmap to display in ImageView. This entire flow is working fine in Android 2.2 and 2.3, whereas it's not functioning with Android 3.0 and 4.0. The bitmap decoded is null in the latter case whereas its fine in 2.x.
下面是code片段我使用..
Here is the code snippet I use..
ImageView imgView = (ImageView) findViewById(R.id.image);
String imageUrl = "my webservice url";
HttpClient httpClient = new DefaultHttpClient();
HttpGet mHttpGetEntity = new HttpGet(imageUrl);
HttpResponse response;
try {
response = httpClient.execute(mHttpGetEntity);
XmlPullParser xpp = XmlPullParserFactory.newInstance().newPullParser();
InputStream is = response.getEntity().getContent();
xpp.setInput(is, "UTF-8");
// use xpp for process
imgView.setImageBitmap(BitmapFactory.decodeStream(is));
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
我怎样才能使这项工作即使有以上的Android 3.0。请指点。
How can I make this work even with Android 3.0 above. Please advice.
推荐答案
您code正在做我的4.0罚款。我要说不担心3.0,因为它是不稳定的版本,没有人会使用它。
your code is doing fine on my 4.0. I would say don't worry about 3.0 since it is unstable version no one will use it.
这篇关于从Web服务中的Android 3.0及以上获得从InputStream中加载问题的ImageView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!