갤러리에서 이미지를 읽어와서 웹DB로 전송하여 저장할때 이미지 크기를 줄여서 전송하려고 합니다.
이런 식으로 이미지 절대경로(selImage_url) 받아보니까,
Cursor c = getContentResolver().query(Uri.parse(data.getData().toString()), null, null, null, null); c.moveToNext(); selImage_url = c.getString(c.getColumnIndex(MediaStore.MediaColumns.DATA));
/mnt/sdcard/DCIM/Camera/~~~.jpg 이런식으로 이미지 경로가 나오더라구요.
그래서 http를 통해서 보낼때,
File file = new File(selImage_url);
ContentBody selImage_file = new FileBody(file, "image/jpeg");
mpEntity.addPart("my_img", selImage_file); //이미지 파일
이런식으로 보내고 있습니다.
비트맵으로 읽어올 경우 createScaledBitmap() 함수를 이용해서 크기를 줄이는게 가능하던데,
저렇게 파일로 읽어올 경우 어떻게 해야 이미지 크기를 줄일 수 있을까요???
제가 사용하던 방법입니다.
public static Bitmap bitmapResize(String filePath, int size) {
int sampleCount = size / MAX_IMAGE_SIZE;
if (sampleCount > 0) {
sampleCount = (sampleCount + 1);
if (sampleCount % 2 == 1)
sampleCount++;
JLog.d("JJY", "bitmapResize sample=" + sampleCount);
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = sampleCount;
return BitmapFactory.decodeFile(filePath, options);
}
else {
JLog.d("JJY", "bitmapResize no sampling");
return BitmapFactory.decodeFile(filePath);
}
}




파일형태로 이미지의 사이즈를 줄일수 있을지...?
파일을 비트맵으로 불러와서 비트맵을 다시 사이즈 줄이면서 파일로 저장후 전송해야하지 않을까 싶습니다.