【发布时间】:2018-05-03 22:47:50
【问题描述】:
我正在尝试使用代码为捕获的图像创建一个单独的文件夹,下面的代码可以正常创建单独的文件夹,并且图像也保存在该文件夹中
我的问题是捕获的图像也出现在 gallery 中,我不想在我的 gallery 中显示它们,有人可以帮我吗?要求
代码:
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;
}
【问题讨论】:
-
只需在该文件夹中放置一个名为
.nomedia的空文件。 -
imageUri = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
-
我认为这个代码图像也出现在画廊中
-
实际上使用上面的代码捕获的图像也出现在我的画廊和单独的文件夹中,我不想在画廊中显示它们
-
i think for this code images also appear in gallaery那你为什么要执行那段代码?