2016-04-12 26 views
-4

私は、画像をキャプチャし、特定のフォルダの中にではなく、DCIM /カメラやギャラリーに保存したい...保存画像アンドロイド

は次のように保存したい:/ sdcard0/DCIM/MyFolderというストレージ。

+1

これまでに何を試しましたか? –

答えて

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(); 
} 
} 
1

を試してみてください、それはあなたが次のコード

private String save(Bitmap bitmap) 
{ 
     File save_path = null; 
     if (android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED)) 
     { 
      try 
      { 
       File sdCard = Environment.getExternalStorageDirectory(); 
       File dir = new File(sdCard.getAbsolutePath() + "/DirName"); 
       dir.mkdirs(); 
       File file = new File(dir, "DirName_"+new SimpleDateFormat("yyyyMMdd_HHmmss").format(Calendar.getInstance().getTime())+ ".png"); 
       save_path = file; 
       ByteArrayOutputStream baos = new ByteArrayOutputStream(); 
       bitmap.compress(Bitmap.CompressFormat.PNG, 100,baos); 
       FileOutputStream f = null; 
       f = new FileOutputStream(file); 
       MediaScannerConnection.scanFile(this, new String[]{file.getAbsolutePath()}, null, null); 
       if (f != null) 
       { 
        f.write(baos.toByteArray()); 
        f.flush(); 
        f.close(); 
       } 
      } 
      catch (Exception e) 
      { 
       // TODO: handle exception 
      } 
     } 
     return String.valueOf(save_path); 
    } 

これはアウトあなたを助けることを願っを使用することができます

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

手助けすることができる、このいずれかを試してみてください。..

+0

私はDirNameフォルダにのみ画像を保存したい、カメラフォルダにも保存する.... –