2013-05-22 5 views
0

안녕 사용자에게 저장하지 말고 직접 카메라 장치에서 사진을 저장하는 방법을 찾고 있습니다. Camera 클래스를 구현하거나 재정의하지 않습니다. 위의 코드를 사용하고 있습니다. 그것을하는 방법에 대한 아이디어가 있습니까?사용자에게 묻지 않고 카메라에서 사진을 자동 저장하는 방법 (간편한 방법)

TextReader tr = new TextReader(TextReader.DIRECTORY_EMPRESAS); 
String path = TextReader.PARENT_PATH + "/" + TextReader.DIRECTORY_IMAGES; 
String dataAtual = new SimpleDateFormat("yyMMddHHmmss").format(new Date()); 

if(tr.verificaDiretorios(path)){ 
    String pictureName = dataAtual + DADOS.get(0) + ".jpg"; 
    File pathEmpresa = new File(path + "/" + TextReader.FILE_NAME); 
    File imageFile; 

    if(pathEmpresa.exists()){ 
     imageFile = new File(pathEmpresa, pictureName);   
     Intent i = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); 
     i.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(imageFile)); 
     //startActivity(i); 
     startActivityForResult(i, 2); 

    }else{ 
     if(pathEmpresa.mkdir()){   
      imageFile = new File(pathEmpresa, pictureName);  
      Intent i = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); 
      i.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(imageFile)); 
      //startActivity(i); 
      startActivityForResult(i, 2); 
     }else{ 
      throw new IllegalStateException("Não foi possivel criar o diretorio: " +   pathEmpresa); 
     } 
}  

답변

0

Intent으로는이 작업을 수행 할 수 없습니다. Camera 클래스를 사용해야합니다.

은 설명서를 참조하십시오 :

http://developer.android.com/reference/android/hardware/Camera.html


빠른 예 :

Camera camera = camera.open(); 
camera.takePicture(null, null, new Camera.PictureCallback() { 
    public void onPictureTaken(byte[] data, Camera camera) { 
     if (data != null) { 
      Bitmap picture = BitmapFactory.decodeByteArray(data); 
      File f = new File(Environment.getExternalStorageDirectory(), "mydir"); 
      f.mkdirs();//Grab file directory 
      f = new File(f, "mypicturefilename"); //Grab picture file location 
      BufferedOutputStream os = new BufferedOutputStream(new FileOutputStream(f)); 
      picture.compress(CompressFormat.JPEG, os);//Write image to file 
      picture.recycle(); //Clean up 
     } 
    } 
}); 
+0

감사 @Zed SCIO를. 카메라 클래스에서 재정의 할 메소드를 직접 저장해야하는지 알고 있습니까? – Dennis

+0

@Dennis 빠른 예를 들어 답을 수정했습니다. –

+0

나중에 테스트에서 소프트웨어에서 일부 사용자 화를 수행 한 다음 예제를 사용하겠습니다. 감사 – Dennis

관련 문제