android读取Assets图片资源保存到SD卡实例
时间:2022-12-18 19:50: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;
}
}
标签:android,Assets图片,保存SD
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
flutter实现appbar下选项卡切换
2023-06-21 13:35:24
![](https://img.aspxhome.com/file/2023/3/87313_0s.gif)
Java并发编程示例(八):处理线程的非受检异常
2022-03-23 14:15:57
C#实现单位换算器
2022-04-20 07:25:55
![](https://img.aspxhome.com/file/2023/6/116656_0s.jpg)
Android 跨进程通Messenger(简单易懂)
2022-03-24 00:48:25
如何使用Java给您的图片瘦身之Thumbnailator技术
2023-10-31 10:25:52
![](https://img.aspxhome.com/file/2023/0/132030_0s.jpg)
eclipse+maven+spring mvc项目基本搭建过程
2022-12-18 03:50:52
![](https://img.aspxhome.com/file/2023/6/69276_0s.png)
在springboot中对kafka进行读写的示例代码
2023-11-26 00:48:02
![](https://img.aspxhome.com/file/2023/7/60457_0s.png)
java实现合并单元格的同时并导出excel示例
2022-05-15 04:22:38
Java 多用户登录限制的实现方法
2022-04-06 07:32:46
C#实现文件上传及文件下载功能实例代码
2022-12-13 23:57:23
swagger中如何给请求添加header
2023-05-15 14:27:52
![](https://img.aspxhome.com/file/2023/0/62350_0s.png)
读取spring配置文件的方法(spring读取资源文件)
2022-10-08 11:24:21
Android Handler 机制实现原理分析
2022-01-14 23:46:49
![](https://img.aspxhome.com/file/2023/1/91041_0s.jpg)
SSH框架网上商城项目第2战之基本增删查改、Service和Action的抽取
2023-06-21 19:16:23
![](https://img.aspxhome.com/file/2023/4/57494_0s.png)
Java拦截器Interceptor和过滤器Filte的执行顺序和区别
2022-06-01 20:37:11
![](https://img.aspxhome.com/file/2023/2/61142_0s.jpg)
Winform圆形环绕的Loading动画实现代码
2023-09-09 00:13:47
![](https://img.aspxhome.com/file/2023/9/88389_0s.gif)
分析Android常见的内存泄露和解决方案
2023-03-24 03:06:33
![](https://img.aspxhome.com/file/2023/5/137235_0s.jpg)
基于WPF实现绘制地铁路线图
2023-09-08 13:23:12
![](https://img.aspxhome.com/file/2023/0/125900_0s.jpg)
FeignClient如何脱离eureka自定义URL
2022-08-27 01:37:25
详解Java虚拟机管理的内存运行时数据区域
2023-12-04 01:32:35
![](https://img.aspxhome.com/file/2023/4/81334_0s.png)