0
嘗試從URL顯示JPG時,出現圖像出現在ImageView中的問題。我可以打開URLConnection,在InputStream中拉下圖像,將該圖像解碼爲位圖。我甚至可以獲得位圖高度和寬度的值。我將位圖設置爲ImageView,仍然可以獲得Drawable的高度。但是,該圖像仍然沒有出現在我的應用程序中。任何想法,我可能會失蹤?謝謝你的幫助。ImageView中未出現位圖
try{
URL imgURL = new URL(imgLocation);
URLConnection conn = imgURL.openConnection();
conn.connect();
InputStream is = conn.getInputStream();
BufferedInputStream bis = new BufferedInputStream(is, 25);
Bitmap bm = BitmapFactory.decodeStream(bis);
if(bm != null){
System.err.println("Image Height: " + bm.getHeight());
System.err.println("Image Width: " + bm.getWidth());
} else {
System.err.println("bm is null!!!");
}
img.setImageBitmap(bm);
System.err.println("Drawable Height: " + img.getDrawable().getIntrinsicHeight());
} catch (IOException e) {
// Print out the exception that occurred
e.printStackTrace();
}