Android中把Bitmap图片保存到文件中
来源:互联网 发布:php mysql 存储过程 编辑:程序博客网 时间:2024/05/16 08:12
做购彩APP时,打印彩票遇到了一些问题,因为打印的彩票是先生成图片再打印,所以想试试看直接打印资源文件中图片是否有问题。
因此需要先把生成的图片保存下来再放到资源文件中,生成png格式图片代码如下:
String dir = Environment.getExternalStorageDirectory().getAbsolutePath() + "/goucaiapp/";
Bitmap bitmap = InitTextQRCodeUtil.getCustomImage(this);
img_test.setImageBitmap(bitmap);
File file = new File(dir + "printBitmap.png");
Log.v("info", "file.getAbsolutePath()===" + file.getAbsolutePath());
if (! file.exists()) {
try {
if (! file.createNewFile()) {
ToastUtil.showToast(getApplicationContext(), "文件创建失败");
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
try {
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file));
bitmap.compress(Bitmap.CompressFormat.JPEG, 80, bos);
bos.flush();
bos.close();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
在应用中执行上述代码后发现并没有生成相对应的png格式图片,但是也没有报错,没有任何提示信息,网上查了相关资料才知道还需要发送一个系统广播通知终端有图片更新:
Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
Uri uri = Uri.fromFile(file);
intent.setData(uri);
sendBroadcast(intent);
这样执行完代码后才看到保存在文件中的png格式图片。
- Android中把Bitmap图片保存到文件中
- android 保存bitmap图片到sd卡中文件夹
- Android数据存储:获取网络图片把图片保存到SD卡中并从SDk卡中读取(通过Bitmap方法)
- android 保存bitmap到sdk中
- 把图片保存到XML中
- C# 把图片保存到数据库中
- 把图片保存到系统相册中
- Swift中把图片保存到相册
- android工程中把数据保存到文件中的class
- android中把文件保存到sdcard代码实例
- 客户端上传到服务端图片,服务端把图片保存到指定的文件中
- Android保存Bitmap到文件
- Android将Bitmap 以图片形式保存到sd卡中
- 把文件流中的图片按指定的大小保存到指定的文件中
- Android写bitmap对象到文件中
- 04 ImageView中图片保存到文件
- ImageView中图片保存到文件
- ImageView中图片保存到文件
- Flume中的拦截器(Interceptor)介绍与使用
- 将Vim改造为强大的IDE—Vim集成Ctags/Taglist/Cscope/Winmanager/NERDTree/OmniCppComplete
- javaee学习日记之javascript
- ffmpeg参数
- [NOIP模拟赛]酷子集
- Android中把Bitmap图片保存到文件中
- keras:2)函数式(Functional)模型
- 消除“Android NDK: WARNING: APP_PLATFORM”的方法
- POJ 2709 染料问题
- 进程
- ffmpeg工具调研
- 对lf_feature_storage性能测试分析(c测试用例版)
- [.cpp]统计双拼拼音一种方案的重码数
- python批处理实现爬取网页静态图片文件重命名图片统一修改大小等功能