我正在尝试从 URL 获取位图,但我不知道该怎么做。这是我正在使用的网址:
String imgurl = "http://api.twitter.com/1/users/profile_image/859486608";
这是我的方法
public Bitmap loadBitmap(String imgPath) {
String imgUrlStr = imgPath;
Bitmap bitmap = null;
try {
bitmap = BitmapFactory.decodeStream((InputStream)new URL(imgUrlStr).getContent());
}
catch (MalformedURLException e) {
e.printStackTrace();
}
catch (IOException e) {
e.printStackTrace();
}
return bitmap;
}
这是日志输出:
11-08 14:41:23.471: WARN/System.err(2682): java.io.IOException: Stream is closed
11-08 14:41:23.481: WARN/System.err(2682): at java.io.BufferedInputStream.read(BufferedInputStream.java:316)
11-08 14:41:23.481: WARN/System.err(2682): at java.io.FilterInputStream.read(FilterInputStream.java:130)
11-08 14:41:23.481: WARN/System.err(2682): at com.ideal.self.Exa_LoadImageUrlActivity.loadImageFromUrl(Exa_LoadImageUrlActivity.java:73)
11-08 14:41:23.481: WARN/System.err(2682): at com.ideal.self.Exa_LoadImageUrlActivity.onCreate(Exa_LoadImageUrlActivity.java:35)
11-08 14:41:23.481: WARN/System.err(2682): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
11-08 14:41:23.481: WARN/System.err(2682): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
11-08 14:41:23.491: WARN/System.err(2682): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
11-08 14:41:23.491: WARN/System.err(2682): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
11-08 14:41:23.491: WARN/System.err(2682): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
11-08 14:41:23.491: WARN/System.err(2682): at android.os.Handler.dispatchMessage(Handler.java:99)
11-08 14:41:23.491: WARN/System.err(2682): at android.os.Looper.loop(Looper.java:123)
11-08 14:41:23.491: WARN/System.err(2682): at android.app.ActivityThread.main(ActivityThread.java:4627)
11-08 14:41:23.491: WARN/System.err(2682): at java.lang.reflect.Method.invokeNative(Native Method)
11-08 14:41:23.491: WARN/System.err(2682): at java.lang.reflect.Method.invoke(Method.java:521)
11-08 14:41:23.491: WARN/System.err(2682): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
11-08 14:41:23.501: WARN/System.err(2682): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
11-08 14:41:23.501: WARN/System.err(2682): at dalvik.system.NativeStart.main(Native Method)