갤러리 또는 카메라의 이미지로 작동하는 작은 앱을 만들었습니다.메모리에로드하기 전에 Android 이미지 크기를 확인하십시오.
모두 정상적으로 작동하지만 작은 화면과 작은 메모리 크기 (HTC Desire)가있는 장치에서 다른 휴대 전화에서 전체 크기로 다운로드 한 이미지가 있으며 크기가 훨씬 큽니다 (해당 휴대 전화의 8MP 카메라).
내 작은 카메라 거대한 이미지를로드하려고하면 바로 충돌합니다.
그래서 어떤 종류의 검사를 구현하고 해당 이미지를 축소하는 방법은 있지만 올바르게로드합니까?
이미지를로드 한 후에 크기를 조정하지만 충돌이 발생하기 전에 수행해야하는 작업입니다.
Tnx.
InputStream in = null;
try {
in = getContentResolver().openInputStream(data.getData());
} catch (FileNotFoundException e) {
e.printStackTrace();
}
// get picture size.
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeStream(in, null, options);
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
// resize the picture for memory.
int screenH = getResources().getDisplayMetrics().heightPixels; //800
int screenW = getResources().getDisplayMetrics().widthPixels; //480
int width = options.outWidth/screenW;
int height = options.outHeight/screenH;
Log.w("Screen Width", Integer.toString(width));
Log.w("Screen Height", Integer.toString(height));
int sampleSize = Math.max(width, height);
options.inSampleSize = sampleSize;
options.inJustDecodeBounds = false;
try {
in = getContentResolver().openInputStream(data.getData());
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// convert to bitmap with declared size.
Globals.INSTANCE.imageBmp = BitmapFactory.decodeStream(in, null, options);
try {
in.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
내가 인정해야합니다. 내 질문을 코드로 편집합니다. – Balkyto
그래서 나는 그것을 어떤 스크린 에나 넣고, 스크린 크기와 아마도 스크린 밀도를 읽으려고 노력하지만, 여전히 크다. 비율/밀도와 관련하여 뭔가 빠져 있어야합니다. – Balkyto
빅 (800 또는 480)으로 생각합니다. inSampleSize = 8 설정을 시도하십시오. – Blackbelt