国产探花免费观看_亚洲丰满少妇自慰呻吟_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;
}
}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 珲春市| 门源| 聂拉木县| 东光县| 辽阳县| 来安县| 甘孜| 宣恩县| 开原市| 安平县| 凌源市| 北京市| 上犹县| 石嘴山市| 景东| 防城港市| 梓潼县| 读书| 陆丰市| 分宜县| 镇康县| 宝应县| 梁平县| 西安市| 运城市| 沂南县| 秭归县| 松滋市| 永定县| 涡阳县| 虞城县| 青州市| 萝北县| 阿克| 安丘市| 阳朔县| 台东市| 河东区| 邳州市| 庆安县| 西城区|