// 先拼接好一个路径:在内存卡/或是手机内存上做好文件夹
String filePath = Environment.getExternalStorageDirectory()+savePath;
File localFile = new File(filePath);
if (!localFile.exists()) {
localFile.mkdir();
}
//拼接好文件路径和名称
File finalImageFile = new File(localFile, System.currentTimeMillis() + ".jpg");
if (finalImageFile.exists()) {
finalImageFile.delete();
}
try {
finalImageFile.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
FileOutputStream fos = null;
try {
fos = new FileOutputStream(finalImageFile);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
if (bitmap == null) {
Toast.makeText(this, "图片不存在", 0).show();
return;
}
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos);
try {
fos.flush();
fos.close();
Toast.makeText(this, "图片保存在:"+ finalImageFile.getAbsolutePath(), 0).show();
} catch (IOException e) {
e.printStackTrace();
}
//发广播告诉相册有图片需要更新,这样可以在图册下看到保存的图片了
Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
Uri uri = Uri.fromFile(finalImageFile);
intent.setData(uri);
sendBroadcast(intent);
<uses-permission android:name="android.permission.WRITE_SETTINGS" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.READ_OWNER_DATA" />
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有