将图像保存到Android手机中的特定文件夹

时间:2016-04-12 10:21:29

标签: android

我想拍摄图像并将其保存到特定文件夹中而不是DCIM /相机或图库......

想保存如:storage / sdcard0 / DCIM / MyFolder。

3 个答案:

答案 0 :(得分:1)

试试这个可能对你有所帮助

public void takePicture(){
        Intent imgIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
        File imagesFolder = new File(Environment.getExternalStorageDirectory(), "ImagesApp");
        imagesFolder.mkdirs(); // <----
        File image = new File(imagesFolder, "temp.jpg");
        Uri uriSavedImage = Uri.fromFile(image);
        imgIntent.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedImage);
        startActivityForResult(imgIntent,IMAGE_CAPTURE_REQUEST_CODE);
    }

答案 1 :(得分:1)

您可以使用以下代码

Router

希望这会帮助你...

答案 2 :(得分:0)

尝试以下代码

private void createDirectoryAndSaveFile(Bitmap imageToSave, String fileName) {

File direct = new File(Environment.getExternalStorageDirectory() + "/DirName");

if (!direct.exists()) {
    File wallpaperDirectory = new File("/sdcard/DirName/");
    wallpaperDirectory.mkdirs();
}

File file = new File(new File("/sdcard/DirName/"), fileName);
if (file.exists()) {
    file.delete();
}
try {
    FileOutputStream out = new FileOutputStream(file);
    imageToSave.compress(Bitmap.CompressFormat.JPEG, 100, out);
    out.flush();
    out.close();
} catch (Exception e) {
    e.printStackTrace();
}
}