當前位置:首頁 » 安卓系統 » android保存bitmap

android保存bitmap

發布時間: 2024-12-29 04:13:11

⑴ android中Bitmap存為一張圖片

可以用Bitmap.compress函數來把Bitmap對象保存成PNG或JPG文件,然後可以用BitmapFactory把文件中的數據讀進來再生成Bitmap對象。
保存的代碼大概類似於這樣:
try {
FileOutputStream out = new FileOutputStream(filename);
bmp.compress(Bitmap.CompressFormat.PNG, 90, out);
} catch (Exception e) {
e.printStackTrace();
}
具體的可以去查Bitmap和BitmapFactory的幫助文檔。

⑵ android通過HttpClient在網頁中讀取圖片,保存到手機裡面

通過url獲取圖片流,將流轉換成bitmap再將bitmap存放到手機

InputStreambitmapIs=HttpUtils.getStreamFromURL(imageURL);

Bitmapbitmap=BitmapFactory.decodeStream(bitmapIs);

Stringpath="/mnt/sdcard/image/";//這個就是你存放的路徑了。

FilebitmapFile=newFile(path);

FileOutputStreamfos=null;

if(!bitmapFile.exists()){

try{

bitmapFile.createNewFile();

fos=newFileOutputStream(bitmapFile);

bitmap.compress(Bitmap.CompressFormat.PNG,100,fos);

}catch(IOExceptione){

e.printStackTrace();

}finally{

try{

if(fos!=null){

fos.close();

}

}catch(IOExceptione){

e.printStackTrace();

}

}

}

java" wealth="0" />
熱點內容
雲搜卡源碼 發布:2025-07-01 05:32:38 瀏覽:540
華為伺服器怎麼查ip 發布:2025-07-01 05:15:18 瀏覽:370
編譯器中的數據結構 發布:2025-07-01 05:10:53 瀏覽:526
雲伺服器最先跑什麼 發布:2025-07-01 05:02:39 瀏覽:216
微信公眾平台手機上傳視頻 發布:2025-07-01 04:58:53 瀏覽:416
數控車床螺紋編程實例 發布:2025-07-01 04:46:27 瀏覽:424
什麼是安卓品牌尖貨 發布:2025-07-01 04:45:50 瀏覽:699
寫入設備緩存 發布:2025-07-01 04:37:35 瀏覽:433
小雞g4怎麼連安卓 發布:2025-07-01 04:37:25 瀏覽:356
黃金線主圖源碼 發布:2025-07-01 04:35:38 瀏覽:301