2014-12-05 2 views
0

카메라 캡처 후 갤러리에 저장된 이미지의 경로를 가져나는 다음과 같은 코드를 사용하여 카메라를 개방하고

Intent captureImageIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); 

cordova.setActivityResultCallback(this); 

cordova.getActivity().startActivityForResult(captureImageIntent,RESULT_CAPTURE_IMAGE); 

와 내가 돌아갈 수 있도록 onActivityResult 안에 내가, 갤러리에 저장되어있는 path of the image를 얻기 위해 노력하고 있어요 다시 웹 페이지로 이동합니다. 내가 시도 것을 여기

지금까지

Uri uri = intent.getData(); // doesnt work 

내가 MediaStore.EXTRA_OUTPUT을 사용하려고하지만,이 경우 내가 널 의도를 얻고있다.

captureImageIntent.putExtra(MediaStore.EXTRA_OUTPUT, mPhotoUri); 

아무도 경로를 가져올 수 있습니까?

편집

String fileName = "temp.jpg"; 
contentValues values = new ContentValues(); 
values.put(MediaStore.Images.Media.TITLE, fileName); 

      Uri mPhotoUri = cordova.getActivity().getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values); 
+0

mPhotoUri을받는 방법을 게시 할 수 있습니까? –

+0

@HareshChhelana 수정 사항보기 – Hunt

답변

1

세트에 대한 사용자 정의 방법을 정의하고 캡처 한 이미지 경로를 얻을 :

captureImageIntent.putExtra(MediaStore.EXTRA_OUTPUT, setImageUri()); 

이 이미지 bitamp 캡처하기 : 캡처 의도를 사용하여 EXTRA_OUTPUT하는

private String imgPath; 

public Uri setImageUri() { 
    // Store image in dcim 
    File file = new File(Environment.getExternalStorageDirectory() + "/DCIM/", "image" + new Date().getTime() + ".jpg"); 
    Uri imgUri = Uri.fromFile(file); 
    imgPath = file.getAbsolutePath(); 
    return imgUri; 
} 

public String getImagePath() { 
    return imgPath; 
} 

설정 이미지 URI를 디코딩 된 캡처 이미지 경로에서 가져 오기 :

@Override 
protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
    super.onActivityResult(requestCode, resultCode, data); 
    if (resultCode == Activity.RESULT_OK) { 
     if (requestCode == RESULT_CAPTURE_IMAGE) { 
      imgUserImage.setImageBitmap(decodeFile(getImagePath())); 
     } 
    } 
} 

public Bitmap decodeFile(String path) { 
    try { 
     // Decode image size 
     BitmapFactory.Options o = new BitmapFactory.Options(); 
     o.inJustDecodeBounds = true; 
     BitmapFactory.decodeFile(path, o); 
     // The new size we want to scale to 
     final int REQUIRED_SIZE = 70; 

     // Find the correct scale value. It should be the power of 2. 
     int scale = 1; 
     while (o.outWidth/scale/2 >= REQUIRED_SIZE && o.outHeight/scale/2 >= REQUIRED_SIZE) 
     scale *= 2; 
     // Decode with inSampleSize 
     BitmapFactory.Options o2 = new BitmapFactory.Options(); 
     o2.inSampleSize = scale; 
     return BitmapFactory.decodeFile(path, o2); 
    } catch (Throwable e) { 
     e.printStackTrace(); 
    } 
return null; 
}