앨범에서 이미지를 선택하여 가져오는데
최근 나온 고해상도 카메라를 보유한 단말기에서
option.inSampleSize = 2 정도로는 택도없어져서요....
02-23 15:42:43.695: E/GraphicsJNI(4572): VM won't let us allocate 31961088 bytes 이런 에러를 뿜네요....
선택한 Uri를 통해 해당 경로에 있는 사진의 정보를 얻어오고 미리 inSampleSize 값을 정하고 싶은데
어찌 방법이 없을까요...?
현재는 일단 가져와서 createBitmap을 해보고 아웃오브메모리 에러가 나면 캐치해서
inSampleSize 값을 1 증가시켜서 다시 가져오고....
이런식으로 구현하였는데...좀 비효율 적인거 같아서요....
미리 알 수 있따면 원하는 크기만큼 줄여서 받을 수 있을텐데요...
비트맵을 열지않고 하는 소스인데요..
우선 전 디스플레이 사이즈 근처로 샘플링 사이즈
/**
* 이미지가 너무 클 경우 메모리 오버해드가 발생한다.
* 그래서 이미지가 특정 이미지 보다 클 경우 샘플링을 한다.
* @param path 이미지 경로
* @return -1 실패 , 1 기본 샘플링, 2, 4, 8, 16 ....
*/
private int getSamplingSize(String path)
{
if(path == null || path.length()<=0)
return -1;
File file = new File(path);
if(!file.isFile())
return -1;
BitmapFactory.Options o = new BitmapFactory.Options();
o.inJustDecodeBounds = true;
FileInputStream fis;
try {
fis = new FileInputStream(file);
BitmapFactory.decodeStream(fis, null, o);
fis.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return -1;
}catch(IOException e2)
{
e2.printStackTrace();
return -1;
}
int scale = 1;
Display dsp = getDisplaySize();
int MAX_SIZE = (dsp.getHeight() > dsp.getWidth()) ? dsp.getHeight() * 2 : dsp.getWidth() *2;
if (o.outHeight > MAX_SIZE || o.outWidth > MAX_SIZE) {
scale = (int) Math.pow(2, (int) Math.round(Math.log(MAX_SIZE
/ (double) Math.max(o.outHeight, o.outWidth))
/ Math.log(0.5)));
}
return scale;
}




Bitmap getHeight(), getWeight()