歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> Android系統中圖片的讀寫

Android系統中圖片的讀寫

日期:2017/3/1 10:04:06   编辑:Linux編程

讀取手機圖片:
Bitmap bmp=BitmapFactroy.decodeFile("/sdcard/xxx.png");
imageview.setImageBitmap(bmp);
讀取網絡圖片:
URL url=new URL(圖片網址);
URLConection conn=url.openConnection();
conn.connect();
InputStream is=conn.getInputStream();
Bitmap bmp=BitmapFactory.decodeSteam(is);
imageview.setImageBitmap(bm);
存儲圖片?應該是說再網絡上下載圖片到本地吧?
這個比較簡單!
通過InputStream和OutputStream 下載到sdcard即可!

--------------------------------------------------------------------------------
一般來說都會存在應用自己的緩存目錄中,可通過 context.getCacheDir() 獲取。

就一般的FileOutputStream、InputStream就可以。

取的時候可以用 getContentResolver().openInputStream(uri); 這種方式來取到圖片的InputStream

之後 Drawable.createFromStream

可參考:Android開發之簡單圖片浏覽器 讀取SDCard圖片+形成縮略圖+Gallery http://www.linuxidc.com/Linux/2012-12/77110.htm

Copyright © Linux教程網 All Rights Reserved