2013-03-02 8 views
1

다음 코드를 사용하면 비트 맵이 저장되어 갤러리의 "카메라"앨범 끝에 삽입됩니다.앨범에 비트 맵 저장

MediaStore.Images.Media.insertImage(getContentResolver(), bmp, null , null); 

어떻게 앱의 앨범에 비트 맵을 저장하나요?

+0

앱 이름의 디렉토리를 만들고 그 안에 문제를 저장 하시겠습니까 ?? – Shiv

답변

1
private boolean createFolder(String folderName) { 
    // TODO Auto-generated method stub 
    boolean success = true; 
    if(checkforMedia()) 
    { 
     String newFolder = "/OnTheG/"+folderName; 
     String extStorageDirectory = Environment.getExternalStorageDirectory().toString(); 
     File myNewFolder = new File(extStorageDirectory + newFolder); 
     success= myNewFolder.mkdirs(); 
    } 

    else 
    { 
     success=false; 
    } 
    return success; 


} 

use this function to create your folder in sdcard. 

Open the camera using this function to store your clicked image at your folder 


public void takePhoto1() { 
     if (!android.os.Environment.getExternalStorageState().equals(
       android.os.Environment.MEDIA_MOUNTED)) { 
      Toast.makeText(Add_View_Images_Activity.this, 
        "Please insert SDcard for capturing photo.", 
        Toast.LENGTH_SHORT).show(); 
     } else { 

      try { 

       photo1=new File(path+"/"+System.currentTimeMillis()+".jpg"); 
       Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);    
       cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photo1)); 
       cameraIntent.putExtra("return-data", true); 

       startActivityForResult(cameraIntent, 4); 
      } catch (Exception e) { 
       Toast.makeText(Add_View_Images_Activity.this, ""+e, Toast.LENGTH_LONG).show(); 
      } 
     } 

    } 


and If you pick a image from the gallery obtain it's path and then move it to your folder using this function 


    private void moveTheImage(String path) { 
      // TODO Auto-generated method stub 
      // File sd = Environment.getExternalStorageDirectory(); 
      //  File data = Environment.getDataDirectory(); 

      String sourceImagePath= path; 
      System.out.println("Source path>>>>>>>>>"+path); 

      String destinationImagePath= fWrapper.path+getTheName(path); 

      File source= new File(sourceImagePath); 
      File destination= new File(destinationImagePath); 
      Log.d("before copying", ""); 
      if (source.exists()) { 
       try 
       { 
        FileChannel src = new FileInputStream(source).getChannel(); 
        FileChannel dst = new FileOutputStream(destination).getChannel(); 
        dst.transferFrom(src, 0, src.size()); 
        src.close(); 
        dst.close(); 
       } 

       catch (Exception e) { 
        // TODO: handle exception 
       } 
      } 
     } 
+0

갤러리 앱을 열면 카메라, 스크랩북 사진, 자동 업로드 및 기타 앨범이 표시됩니다. 사진을 저장 한 후 갤러리 앱에서 볼 수있는 맞춤 앨범에 저장하고 싶습니다. – primary0

+0

자신의 앨범에있는 사진을 클릭하여 저장해야합니까? 원하는대로 답변을 편집합니다. –

+0

예. 그게 내가 필요한 것입니다. 감사! – primary0

관련 문제