2014-01-22 3 views
0

URI에 대한 이미지 비트 맵을 가져 오려고했지만 다음 오류가 발생합니다.URI에서 비트 맵을 가져 오는 중에 파일을 찾을 수 없습니다.

를 System.err (3102) : java.io.FileNotFoundException : 없음 콘텐츠 제공 : /storage/emulated/0/1.jpg

나는이 시도 코드,

Cursor mCursor; 
    mCursor=activity.getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,mProjection,null, null, MediaStore.Images.Media.DEFAULT_SORT_ORDER); 

    if (mCursor != null) { 
     mCursor.moveToFirst(); 
     do { 
      String strPath = mCursor.getString(mCursor 
        .getColumnIndex(MediaStore.Images.Media.DATA)); 
         try { 
       Bitmap bitmap = MediaStore.Images.Media.getBitmap(
         activity.getContentResolver(), Uri.parse(strPath)); 
            //Here i'm using bitmap 
         } catch (FileNotFoundException e) { 
       Log.i("Exception", 
         "Image file not found: " + e.getMessage()); 
       e.printStackTrace(); 
         } catch (IOException e) { 
       Log.i("Exception", 
         "Input Output Failure: " + e.getMessage()); 
       e.printStackTrace(); 
      } 

     } while (mCursor.moveToNext()); 
+0

이 질문에서보세요 >>> http://stackoverflow.com/questions/20067508/get-real-path-from-uri-android -킷 캣 -new-storage-access-framework – 2Dee

답변

0

GET 경로 URI에서와 이미지를 얻을이 경로를 사용

public String getRealPathFromURI(Uri contentUri) { 
    try { 
     String[] proj = { MediaStore.Images.Media.DATA }; 
     @SuppressWarnings("deprecation") 
     Cursor cursor = managedQuery(contentUri, proj, null, null, null); 
     int column_index = cursor 
       .getColumnIndexOrThrow(MediaStore.Images.Media.DATA); 
     cursor.moveToFirst(); 
     return cursor.getString(column_index); 
    } catch (Exception e) { 
     return contentUri.getPath(); 
    } 
} 
0
protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
     // TODO Auto-generated method stub 
     super.onActivityResult(requestCode, resultCode, data); 
     if (requestCode == 2 && resultCode == RESULT_OK) { 

      Uri selectedImage = data.getData(); 
      String[] filePathColumn = { MediaStore.Images.Media.DATA }; 
      Cursor cursor = getContentResolver().query(selectedImage, 
        filePathColumn, null, null, null); 
      cursor.moveToFirst(); 
      int columnIndex = cursor.getColumnIndex(filePathColumn[0]); 
      String picturePath = cursor.getString(columnIndex); 
      cursor.close(); 
      File file = new File(picturePath); 
      Bitmap bmpp = decodeAndResizeFile(file); 
// get bitmap that which image select you and set bmpp to imageview 

     } 
관련 문제