2017-02-13 4 views
0

내가 장치의 메모리에서 이미지 경로를 얻을 안드로이드 API (23) 내 CircleImageView에 이미지를 설정하고 데이터베이스에이 문자열 경로를 저장하기 위해 노력하고있어에 이미지를 설정하지 않은 API 19 이전 버전에서 작동하지만 Android 버전 API 23을 사용하는 Genymotion의 가상 장치에서는 작동하지 않습니다. 선택한 이미지가 ImageView에 표시되지 않습니다.setImageDrawable는 API23

mCurrentImagePath = FileUtils.getPath(getActivity(), selectedImageUri); 
Log.d(TAG, "mCurrentImagePath: " + mCurrentImagePath); 

// Update client's picture 
if (mCurrentImagePath != null && !mCurrentImagePath.isEmpty()) { 
    fragmentEditPicture.setImageDrawable(new BitmapDrawable(getResources(), 
      FileUtils.getResizedBitmap(mCurrentImagePath, 512, 512))); 
} 

이미지 경로가 mCurrentImagePath: /storage/emulated/0/Download/56836_(5-27-2006 2-28-40)(1920x1200).JPG이다 : 나는 이미지 뷰에 이런 식으로 이미지를 설정하고있다.

이것이 작동하지 않는 이유를 알고 계십니까?

+1

런타임에 필요한 권한을 요청 했습니까? –

+0

@OgnianGloushkov No. 오류 또는 예외가 발생하지 않습니다. 단지 이미지를 설정하지 않습니다. –

답변

1

사용하는 방법에 문제가 있습니다. FileUtils.getResizedBitmap(). 문제를 재현 할 샘플 프로젝트를 만들었습니다. 샘플 프로젝트에서 잘 작동합니다. 아래의 코드 스 니펫을 사용할 때 장치의 메모리에서 이미지를로드하는 데 문제가 없어야합니다.

public static Bitmap getResizedBitmap(String imagePath, int width, int height) { 
    Bitmap bitmap = BitmapFactory.decodeFile(imagePath); 
    Bitmap resizedBitmap = Bitmap.createScaledBitmap(bitmap, width, height, false); 
    // Recycling the bitmap, because it's already used and not needed anymore 
    bitmap.recycle(); 
    return resizedBitmap; 
} 
+0

원래의'bitmap'을 사용한 후 그것을 재활용하십시오. 먼저 BitmapFactory.Options.inJustDecodeBounds를 사용하십시오. –

+0

@EugenPechanec 버디, 미안, 네가 정확히 말한 것을 못 얻었 어 !! 나는 android.this에 새로운입니다 [FileUtils.getResizedBitmap()] (http://codepad.org/c33ilHxK). 메소드에서 options.inJustDecodeBounds = false를 사용합니다. 나는 정확히 어떻게합니까? 당신의 제안을 이해함에 따라 나는이 방법으로 [link] (http://codepad.org/oiskWKwf)를 사용했다. 그러나 나는 [link] (http://codepad.org/wqGYmUHx) 오류가있다. . 미안 해요. 고마워요. –

+0

'mCurrentImagePath'는 이미지가 선택한 uri가 아닌 경로입니다. –