android讀取Assets圖片資源保存到SD卡實例
更新時間:2013年07月02日 15:01:12 作者:
本文為大家詳細介紹下android讀取Assets圖片資源保存到SD卡的具體實現(xiàn),感興趣的各位可以參考下哈,希望對大家有所幫助
復制代碼 代碼如下:
public class ReadBitmap {
public void readByte(Context c, String name, int indexInt) {
byte[] b = null;
int[] intArrat = c.getResources().getIntArray(indexInt);
try {
AssetManager am = null;
am = c.getAssets();
InputStream is = am.open(name);
for (int i = 0; i < intArrat.length; i++) {
b = new byte[intArrat[i]];
// 讀取數(shù)據(jù)
is.read(b);
saveMyBitmap(Bytes2Bimap(b), MainActivity.DIR+name+i+".jpg");
}
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
public static Bitmap Bytes2Bimap(byte[] b) {
if (b.length != 0) {
return BitmapFactory.decodeByteArray(b, 0, b.length);
} else {
return null;
}
}
public static boolean saveMyBitmap(Bitmap bmp, String path) {
File f = new File(path);
try {
f.createNewFile();
FileOutputStream fOut = new FileOutputStream(f);
bmp.compress(Bitmap.CompressFormat.JPEG, 100, fOut);
fOut.flush();
fOut.close();
return true;
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
return false;
}
}
相關文章
Android 如何使用SQLite保存數(shù)據(jù)
對于重復數(shù)據(jù)或結構化數(shù)據(jù)(例如聯(lián)系信息),將數(shù)據(jù)保存到數(shù)據(jù)庫是理想選擇,SQL 數(shù)據(jù)庫的主要原則之一是架構,即數(shù)據(jù)庫組織方式的正式聲明,本篇文章介紹在 Android 上使用 SQLite 數(shù)據(jù)庫,感興趣的朋友一起看看吧2024-03-03
Android自定義View實現(xiàn)鐘擺效果進度條PendulumView
這篇文章主要介紹了Android自定義View實現(xiàn)鐘擺效果進度條PendulumView,具有一定的參考價值,感興趣的小伙伴們可以參考一下2016-09-09
android實現(xiàn)session保持簡要概述及實現(xiàn)
其實sesion在瀏覽器和web服務器直接是通過一個叫做name為sessionid的cookie來傳遞的,所以只要在每次數(shù)據(jù)請求時保持sessionid是同一個不變就可以用到web的session了,感興趣的你可以參考下本文或許對你有所幫助2013-03-03
Android ExpandableListView使用方法案例詳解
這篇文章主要介紹了Android ExpandableListView使用方法案例詳解,本篇文章通過簡要的案例,講解了該項技術的了解與使用,以下就是詳細內容,需要的朋友可以參考下2021-08-08

