Android 利用url获取Bitmap图片
生活随笔
收集整理的這篇文章主要介紹了
Android 利用url获取Bitmap图片
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
編程中我們經常需要通過url獲取網絡上的圖片。下面將相關代碼做一下總結
注意:Android中這一操作必須在異步線程中進行
public class BitmapUtil {public static Bitmap getBitmap(String url) {URL imageURL = null;Bitmap bitmap = null;Log.e("inuni","URL = "+url);try {imageURL = new URL(url);} catch (MalformedURLException e) {e.printStackTrace();}try {HttpURLConnection conn = (HttpURLConnection) imageURL.openConnection();conn.setDoInput(true);conn.connect();InputStream is = conn.getInputStream();bitmap = BitmapFactory.decodeStream(is);is.close();} catch (Exception e) {e.printStackTrace();}return bitmap;} } 《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀總結
以上是生活随笔為你收集整理的Android 利用url获取Bitmap图片的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: MySQL创建视图(CREATE VIE
- 下一篇: 自定义一个SharedPreferenc