Intent intent = new Intent(Intent.ACTION_PICK) ;
intent.setDataAndType(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, MediaStore.Images.Media.CONTENT_TYPE) ;
startActivityForResult(intent, 0);
@Override
public void onActivityResult( int requestCode, int resultCode, Intent data ) {
if( requestCode == 0 ) {
if(data != null) {
try {
Uri selPhotoUri = getNewTempPhotoUri(data.getData());
Bitmap selPhoto = Images.Media.getBitmap(getContentResolver(), selPhotoUri);
selPhoto = Bitmap.createScaledBitmap(selPhoto, 100, 100, true);
imagebutton_user.setImageBitmap(selPhoto) ;
check_photo = 1;
} catch (IOException e)
{
}
}
}
}
onActivityResult 에서 비트맵을 로드합니다.
Images.Media.getBitmap(getContentResolver(), selPhotoUri); <--이부분 비트맵을 로드하는 부분에서
Out of Memory 오류가 발생합니다. 사진의 용량이 3M이상이라 Out of Memory가 발생하는데 해결하기 위해 자료를
찾아보니 잘나오지가 않네요 해결방법으로 제시된걸 보니 전부 아래와같이 옵션을 이용해서 해결을 하도록 설명이 되어있는데
BitmapFactory.Options options =
new
BitmapFactory.Options();
options.inSampleSize = 4;
Bitmap orgImage = BitmapFactory.decodeFile(“/sdcard/test.jpg”, options);
도움이 되실지는 모르겠지만...
inSampleSize 에서 크기를 좀 더 줄여보시는건 어떨지요?
전 2M 파일 띄우는데 Out of Memory 가 떠서 inSampleSize 를 8로 주니 해결됐습니다.