안녕하세요, 안드로이드 공부중인 초보입니다.
특정버튼을 클릭하면 "ACTION_PICK"을 통해서 갤러리 화면을 띄우고, 이미지를 선택해서 원하는 이미지뷰에 선택한 이미지를 띄우려고 헀는데요,,
원래 Bitmap image_bitmap = MediaStore.Images.Media .getBitmap(getContentResolver(), data.getData());
(이걸로 받아온 비트맵 값) content://media/external/images/media/10082
이걸로 이미지를 그리면, 선택한이미지가 이미지 뷰에 잘 그려졌습니다.
(절대경로를 구하고 그걸 이미지 뷰에 씌우는 방법을 하려는 이유는, 이미지 절대경로를 String으로 저장했다가 다시 앱을 킬때도 저장된 경로로 이미지를 띄우려 해서 입니다. 이 위의 컨텍스트 경로를 저장했다가 리스트 뷰로 이미지를 그리려 하니까 실패하더라구요..)
그래서 이미지의 절대 경로를 구해서 그리려고 시도해봤습니다 (기종 : 갤럭시s6 - 내부 갤러리에 저장된 이미지)
Uri selectedImg_uri;
this.selectedImg_uri = Uri.parse(selectedImg_path);
현재 selectedImg_uri 이거 값이 /storage/emulated/0/Download/13659028_1035067996585531_2022603899746916935_n.jpg 이거로 되어있습니다.
시도 방법1)
//그리기
image_selected.setImageURI(selectedImg_uri);
시도방법2)
File img_pathFile = new File(String.valueOf(selectedImg_uri));
Bitmap bm_imgPath;
BitmapFactory.Options bm_options;
try{
bm_imgPath=BitmapFactory.decodeFile(img_pathFile.getAbsolutePath());
System.out.println("Try(aaaa)");
} catch (OutOfMemoryError e){
bm_options = new BitmapFactory.Options();
bm_options.inSampleSize = 2;
bm_imgPath = BitmapFactory.decodeFile(img_pathFile.getAbsolutePath(), bm_options);
System.out.println("OutOfMemoryError(aaaa)");
} catch (Exception e){
bm_imgPath = null;
System.out.println("Exception(aaaa)");
}
System.out.println("이거 널???(aaaa):"+String.valueOf(bm_imgPath)); (→네,, 이게 null이 뜹니다..);
System.out.println("bm_imgPath(aaaa):"+String.valueOf(img_pathFile.getAbsolutePath()));
//그리기 image_selected.setImageBitmap(bm_imgPath);