iis服务器助手广告广告
返回顶部
首页 > 资讯 > 移动开发 >android读取Assets图片资源保存到SD卡实例
  • 862
分享到

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

sdsd卡Android 2022-06-06 10:06:48 862人浏览 泡泡鱼
摘要

代码如下: public class ReadBitmap { public void readByte(Context c, String name, int indexI

代码如下:
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;
}
}
您可能感兴趣的文章:Android实现复制Assets文件到SD卡Android编程读取Assets所有文件(遍历每一个文件夹)并存入sdcard的方法Android获取assets文件夹中的数据并写入SD卡示例Android复制assets文件到SD卡


--结束END--

本文标题: android读取Assets图片资源保存到SD卡实例

本文链接: https://www.lsjlt.com/news/27397.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作