使用以下代碼顯示來自url的imageview中的圖像。
ImageView mImageView = (ImageView)findViewById(R.id.mImageView1);
URL url = new URL(address);
InputStream content = (InputStream)url.getContent();
Drawable d = Drawable.createFromStream(content , "src");
mImageView.setImageDrawable(d);
而且還使用下面的代碼。
try {
URL url = new URL(imageUrl);
HttpGet httpRequest = null;
httpRequest = new HttpGet(url.toURI());
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response = (HttpResponse) httpclient.execute(httpRequest);
HttpEntity entity = response.getEntity();
BufferedHttpEntity b_entity = new BufferedHttpEntity(entity);
InputStream input = b_entity.getContent();
Bitmap bitmap = BitmapFactory.decodeStream(input);
ImageView mImageView = (ImageView) findViewById(R.id.mImageView);
mImageView.setImageBitmap(bitmap);
} catch (MalformedURLException e) {
Log.e("log", "bad url", t);
} catch (IOException e) {
Log.e("log", "io error", t);
}
試試這個: 位圖位= BitmapFactory.decodeStream((InputStream的)新的網址(URL).getContent()); mImageView.setImageBitmap(bitmap); – AkashG 2012-07-07 06:36:42
@AkashG同樣的結果。與HTTPS一起使用時不加載圖像。 – tamsler 2012-07-07 06:40:24
@tamsler檢查答案在http://stackoverflow.com/questions/11241137/inputstream-read-has-no-response-when-downloading-large-imagesize-300k/11241660#11241660 – Khan 2012-07-07 07:04:44