当前位置: 移动技术网 > 移动技术>移动开发>Android > android读取Assets图片资源保存到SD卡实例

android读取Assets图片资源保存到SD卡实例

2019年07月24日  | 移动技术网移动技术  | 我要评论
复制代码 代码如下:

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;
}
}

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网