android讀取Assets圖片資源保存到SD卡實(shí)例
更新時間:2013年07月02日 15:01:12 作者:
本文為大家詳細(xì)介紹下android讀取Assets圖片資源保存到SD卡的具體實(shí)現(xiàn),感興趣的各位可以參考下哈,希望對大家有所幫助
復(fù)制代碼 代碼如下:
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;
}
}
相關(guān)文章
解決Android SELinux權(quán)限問題記錄分析
這篇文章主要為大家介紹了解決Android SELinux權(quán)限問題記錄分析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-11-11android中SharedPreferences實(shí)現(xiàn)存儲用戶名功能
本篇文章主要介紹了android中SharedPreferences實(shí)現(xiàn)保存用戶名功能,詳細(xì)的介紹了SharedPreferences的功能,需要的朋友可以參考下2017-04-04Android跨進(jìn)程拋異常的原理的實(shí)現(xiàn)
這篇文章主要介紹了Android跨進(jìn)程拋異常的原理的實(shí)現(xiàn),小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-11-11Flutter Reusable Lottie Animations技巧
這篇文章主要為大家介紹了Flutter Reusable Lottie Animations技巧,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-12-12Android中PopupWindow響應(yīng)返回鍵并關(guān)閉的2種方法
這篇文章主要介紹了Android中PopupWindow響應(yīng)返回鍵并關(guān)閉的2種方法,本文講解了最簡單的方法、最通用的方法,需要的朋友可以參考下2015-04-04Android實(shí)現(xiàn)雙向滑動特效的實(shí)例代碼
這篇文章主要介紹了Android實(shí)現(xiàn)雙向滑動特效的實(shí)例代碼,具有很好的參考價值,希望對大家有所幫助,一起跟隨小編過來看看吧2018-05-05android自定義按鈕示例(重寫imagebutton控件實(shí)現(xiàn)圖片按鈕)
由于項(xiàng)目這種類型的圖片按鈕比較多,所以重寫了ImageButton類,現(xiàn)在把代碼分享給大家,需要的朋友可以參考下2014-03-03