gpt4 book ai didi

android - 从 SD 卡和图库中删除图像

转载 作者:行者123 更新时间:2023-11-30 04:16:06 27 4
gpt4 key购买 nike

我是这样保存一些图片到SD卡上的:

File dir = new File(fullPath);
if (!dir.exists()) {
dir.mkdirs();
}
String id = Integer.toString(i+1);
OutputStream fOut = null;
File file = new File(fullPath, id);
file.createNewFile();
fOut = new FileOutputStream(file);

// 100 means no compression, the lower you go, the stronger the compression
bm.compress(Bitmap.CompressFormat.PNG, 100, fOut);
fOut.flush();
fOut.close();

MediaStore.Images.Media.insertImage(this.getContentResolver(), file.getAbsolutePath(), file.getName(), file.getName());

但是,当我从 SD 卡中删除这些图像时,它们会保留在图库中。

File path = new File(path);
File[] lstFile;

if(path.exists()){
lstFile = path.listFiles();
for(int i =0; i<lstFile.length;i++){
File file = lstFile[i];
file.delete();
}
path.delete();
}

为什么这些图像会保留在图库中,我该如何删除它们?有没有办法首先避免将这些图像保存在图库中?

最佳答案

哦!我没有注意到

“有没有办法首先避免将这些图像保存在图库中?”

是的,有。移除

 MediaStore.Images.Media.insertImage(this.getContentResolver(), file.getAbsolutePath(), file.getName(), file.getName());

并仅使用 File 类而不是 MediaStore 类保存文件,其目的正是帮助管理画廊。

关于android - 从 SD 卡和图库中删除图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9994388/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com