我目前有一个应用程序,它将在单击按钮时拍照。但是,照片将存储在应用程序目录下的“图片”文件夹中。如何将图像保存或复制到可在常规Android照片库中查看的常规DCIM文件夹。
一个很好的例子!
MainActivity.java中我指定目录的位置
private File createImageFile() throws IOException{
//Create an image file name
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
String imageFileName = "JPEG_" + timeStamp + "_";
File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES);
File image = File.createTempFile(
imageFileName, //prefix
".jpg", //suffix
storageDir //directory
);
//Save a file: path
currentPhotoPath = image.getAbsolutePath();
return image;
}
答案 0 :(得分:0)
public void addImageToGallery(final String filePath, String imageName,Context mContext,String description) {
ContentValues values = new ContentValues();
values.put(MediaStore.Images.Media.DATE_TAKEN, System.currentTimeMillis());
values.put(MediaStore.Images.Media.MIME_TYPE, "image/jpeg");
values.put(MediaStore.MediaColumns.DATA, filePath);
//adding images to Media Gallery using MediaStore
try {
MediaStore.Images.Media.insertImage(mContext.getContentResolver(), filePath, imageName, description);
}catch (Exception e){
Log.i("Error","error in inserting image");
e.printStackTrace();
}
}
然后称呼它:
addImageToGallery(filepath,imageName,this,description);