Bitmap 클래스에 압축 메소드가 있음을 알기 전에이 메소드를 작성했습니다.Android 비트 맵 압축
/**
* Calcuate how much to compress the image
* @param options
* @param reqWidth
* @param reqHeight
* @return
*/
public static int calculateInSampleSize(BitmapFactory.Options options,int reqWidth, int reqHeight) {
final int height = options.outHeight;
final int width = options.outWidth;
int inSampleSize = 1; // default to not zoom image
if (height > reqHeight || width > reqWidth) {
final int heightRatio = Math.round((float) height/ (float) reqHeight);
final int widthRatio = Math.round((float) width/(float) reqWidth);
inSampleSize = heightRatio < widthRatio ? heightRatio : widthRatio;
}
return inSampleSize;
}
/**
* resize image to 480x800
* @param filePath
* @return
*/
public static Bitmap getSmallBitmap(String filePath) {
File file = new File(filePath);
long originalSize = file.length();
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(filePath, options);
// Calculate inSampleSize based on a preset ratio
options.inSampleSize = calculateInSampleSize(options, 480, 800);
// Decode bitmap with inSampleSize set
options.inJustDecodeBounds = false;
Bitmap compressedImage = BitmapFactory.decodeFile(filePath, options);
return compressedImage;
}
궁금 해서요, 내가이 일을 계속 사용하거나, 하나의 내장 사용하도록 전환해야한다는 Compress
방법에 내장 된 비교? 차이점은 무엇입니까? 당신은 당신이 SampleSize
을 이미지의 품질의 느슨한 많이 사용하지 않을 것이기 때문에 이미지를 크기를 조정하는 위의 코드에서 뭐하는
이것을 확인하십시오. http://stackoverflow.com/questions/31156501/what-is-the-difference-between-compressing-image-and-resizing-image-android –