国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

android讀取Assets圖片資源保存到SD卡實例

2020-04-11 12:05:26
字體:
來源:轉載
供稿:網友
復制代碼 代碼如下:

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]];
// 讀取數據
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;
}
}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 凤翔县| 通化县| 蒙城县| 苏州市| 昭通市| 同德县| 江都市| 庆城县| 阜新| 东宁县| 临武县| 衡山县| 南川市| 长葛市| 白山市| 昭通市| 高陵县| 奉化市| 珠海市| 镇江市| 罗田县| 教育| 集安市| 太保市| 阿瓦提县| 莲花县| 东兴市| 科技| 咸丰县| 吉安市| 神池县| 紫金县| 莒南县| 西贡区| 肇州县| 平遥县| 正宁县| 五家渠市| 淳化县| 镇雄县| 夹江县|