Android 如何为捕获的图像创建单独的专用文件夹?
我正在尝试创建一个单独的文件夹为捕获的图像使用的代码和下面的代码是工作良好的创建单独的文件夹和图像也保存在该文件夹 我的问题是捕获的图像也出现在图库中,我不想在我的图库中显示它们,请有人帮助我,我需要做什么 代码:Android 如何为捕获的图像创建单独的专用文件夹?,android,android-camera,Android,Android Camera,我正在尝试创建一个单独的文件夹为捕获的图像使用的代码和下面的代码是工作良好的创建单独的文件夹和图像也保存在该文件夹 我的问题是捕获的图像也出现在图库中,我不想在我的图库中显示它们,请有人帮助我,我需要做什么 代码: 它出现在Gallery中是因为您使用的是getExternalStorageDirectory(),这将返回所有应用程序都可以访问的公共路径。因此,一种解决方案是使用私有外部路径context.getExternalFilesDir(Environment.DIRECTORY\u P
它出现在Gallery中是因为您使用的是
getExternalStorageDirectory()
,这将返回所有应用程序都可以访问的公共路径。因此,一种解决方案是使用私有外部路径context.getExternalFilesDir(Environment.DIRECTORY\u PICTURES),folderName)
,保存在此处的文件将无法被MediaScanner访问,因此在库中不可见,尽管它们将在删除应用程序时被删除。只需在该文件夹中放置一个名为.nomedia
的空文件。imageUri=getContentResolver()。插入(MediaStore.Images.Media.EXTERNAL\u CONTENT\u URI,值);我认为对于此代码,图像也会出现在gallaery中。实际上,使用上述代码捕获的图像也会出现在我的库和单独的文件夹中,我不想在库中显示它们我认为对于此代码,图像也会出现在gallaery中
,那么为什么要执行此代码?
ContentValues values = new ContentValues();
values.put(MediaStore.Images.Media.TITLE, "New Picture");
values.put(MediaStore.Images.Media.DESCRIPTION, "From your Camera");
imageUri = getContentResolver().insert(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
startActivityForResult(intent, Constants.CAMERA_REQUEST_CODE);
private void onCaptureImageResult(Intent data) {
Bitmap bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), imageUri);
File compressedFile1 = Utilities.saveImage(this, bitmap);
}
public static File saveImage(Context context, Bitmap imgBitmap) {
File mediaFile = null;
try {
//Bitmap imgBitmap = (Bitmap) data.getExtras().get("data");
File sd = Environment.getExternalStorageDirectory();
File imageFolder = new File(sd.getAbsolutePath() + File.separator +
".FOSImages");
if (!imageFolder.isDirectory()) {
imageFolder.mkdirs();
}
mediaFile = new File(imageFolder + File.separator + "fos_" +
System.currentTimeMillis() + ".jpg");
FileOutputStream fileOutputStream = new FileOutputStream(mediaFile);
imgBitmap.compress(Bitmap.CompressFormat.JPEG, 90, fileOutputStream);
fileOutputStream.close();
return mediaFile;
} catch (Throwable throwable) {
throwable.printStackTrace();
}
return mediaFile;
}