질문 내용 :
아래와 같이 CP를 통해 이미지 경로를 주고 요기서 이미지를 가져와
보여주려고 합니다.
하지만 이미지가 큰 경우 outofmemory로 인해 이미지를 줄여야 했습니다
현재 아래 코드로 구현해 작게 하여 보이긴 하는데 매 이미지에 적용되다 보니
상당히 느려지는 문제가 발생 했습니다.
그래서 이미지를 리사이즈하는 빠른 방법이나. URI 에서 불러올때 작게 보는
방법을 알고싶습니다.
Ps. Thumbnails은 사용해보았지만 Media와 매치문제로 배제하였습니다.
Uri imageFileUri = Uri.withAppendedPath(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,mid.get_id() );
Display currentDisplay = getWindowManager().getDefaultDisplay();
int dw = currentDisplay.getWidth();
int dh = currentDisplay.getHeight() / 2 - 100;
try {
BitmapFactory.Options bmpFactoryOptions = new BitmapFactory.Options();
bmpFactoryOptions.inJustDecodeBounds = true;
Bitmap bmp = BitmapFactory
.decodeStream(getContentResolver().openInputStream(
imageFileUri), null, bmpFactoryOptions);
int heightRatio = (int) Math.ceil(bmpFactoryOptions.outHeight / (float) dh);
int widthRatio = (int) Math.ceil(bmpFactoryOptions.outWidth / (float) dw);
if (heightRatio > 1 && widthRatio > 1) {
if (heightRatio > widthRatio) {
bmpFactoryOptions.inSampleSize = heightRatio;
} else {
bmpFactoryOptions.inSampleSize = widthRatio;
}
}
bmpFactoryOptions.inJustDecodeBounds = false;
bmp = BitmapFactory
.decodeStream(getContentResolver().openInputStream(
imageFileUri), null, bmpFactoryOptions);
/////
Bitmap mView = Bitmap.createBitmap(bmp.getWidth(), bmp
.getHeight(), bmp.getConfig());
Canvas canvas = new Canvas(mView);
Paint paint = new Paint();
canvas.drawBitmap(bmp, 0, 0, paint);
//결과영상
imgView = (ImageView)convertView.findViewById(R.id.imageview1);
imgView.setImageBitmap(mView);
} catch (FileNotFoundException e) {
Log.v("ERROR", e.toString());
}