19
Android从URL加载到位图
我有一个关于从网站加载图像的问题。我使用的代码是: Display display = getWindowManager().getDefaultDisplay(); int width = display.getWidth(); int height = display.getHeight(); Bitmap bit=null; try { bit = BitmapFactory.decodeStream((InputStream)new URL("http://www.mac-wallpapers.com/bulkupload/wallpapers/Apple%20Wallpapers/apple-black-logo-wallpaper.jpg").getContent()); } catch (Exception e) {} Bitmap sc = Bitmap.createScaledBitmap(bit,width,height,true); canvas.drawBitmap(sc,0,0,null); 但是它总是返回一个空指针异常,程序崩溃了。该URL有效,并且似乎适用于其他所有人。我正在使用2.3.1。