2017-11-20 17 views
0

내 스크린에 4 개의 이미지 뷰가 있고 카메라의 이미지를 캡처하여 표시합니다. 이제 이미지를 서버에 업로드하려고합니다. 그래서 그 경로를 얻기 위해 아래 코드를 사용했지만 예외를 통해. 카메라에서 캡처 한 이미지보기에서 이미지를 서버로 업로드 할 수 있습니까 (이미지를 메모리에 저장하지 않고).이미지 뷰에서 캡쳐 된 이미지의 경로를 가져 와서 서버에 업로드

  if (requestCode == 1&& resultCode == RESULT_OK) 
       { 
        Bitmap photo = (Bitmap) data.getExtras().get("data"); 
        purchase_Img_1.setImageBitmap(photo); 
        Uri tempUri = getImageUri(getApplicationContext(), photo); 
        File finalFile = new File(getRealPathFromURI(tempUri)); 

       } 

    public Uri getImageUri(Context inContext, Bitmap inImage) { 
     ByteArrayOutputStream bytes = new ByteArrayOutputStream(); 
     inImage.compress(Bitmap.CompressFormat.JPEG, 100, bytes); 
     String path = MediaStore.Images.Media.insertImage(inContext.getContentResolver(), inImage, "Title", null); 
     return Uri.parse(path); 
    } 

public String getRealPathFromURI(Uri uri) { 
    Cursor cursor = getContentResolver().query(uri, null, null, null, null); 
    cursor.moveToFirst(); 
    int idx = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA); 
    return cursor.getString(idx); 
} 
+1

[카메라 의도를 사용하여 안드로이드에서 캡처 한 이미지의 경로 가져 오기] (https://stackoverflow.com/questions/20327213/getting-path-of-captured-image-in-android-using-camera-intent)) – Prem

+0

예외가 발생합니까? – Vij

답변

1
Getting path of captured image from imageviews 

경로가 없습니다. 경로가 없습니다. 당신은 비트 맵을 가지고 그것들을 뷰에 배치했습니다.

Uri tempUri = getImageUri(getApplicationContext(), photo); 

여기서는 MediaStore를 사용하여 비트 맵을 저장했습니다. 너 우릴 돌려 줬어.

해당 URI에 대한 입력 스트림을 열고 바이트를 읽고 업로드 할 수 있습니다.

그러나 MediaStore를 사용하여 비트 맵을 파일에 저장했습니다. 비트 맵을 ByteArrayOutputStream으로 압축하고 결과 바이트 배열을 업로드하는 것이 바람직하지 않은 경우

0

해당 코드의 대부분을 제거하십시오. compress()을 사용하여 Bitmap을 파일로 저장하십시오. 이제 파일의 위치를 ​​알고 서버 업로드 프로세스에 사용할 수 있습니다.