我正在根据此链接调整图像大小。
图像大小为 3264x2448,计算样本大小后现在为 24,但图像旋转 90 度(左)。
当宽度大于高度时会发生这种情况。
我被困住了。无法解决。
I am using accroding to http://developer.android.com/training/displaying-bitmaps/load-bitmap.html
public static String getCompressedImagePath(String orgImagePath,
String storeImagePath) {
if (orgImagePath == null) {
return null;
}
Bitmap bitmap = decodeSampledBitmapFromResource(orgImagePath, 100, 100);
String absolutePath = "";
FileOutputStream fos = null;
try {
fos = new FileOutputStream(storeImagePath);
bitmap.compress(getCompressionFormatType(orgImagePath),
IMAGE_COMPRESS_FACTOR, fos);
fos.flush();
absolutePath = storeImagePath;
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (NullPointerException e) {
e.printStackTrace();
} finally {
try {
if (fos != null) {
fos.close();
fos = null;
}
} catch (Exception e) {
e.printStackTrace();
}
}
return absolutePath;
}
public static Bitmap decodeSampledBitmapFromResource(String orgImagePath,
int reqWidth, int reqHeight) {
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(orgImagePath, options);
options.inSampleSize = calculateInSampleSize(options, reqWidth,
reqHeight);
options.inJustDecodeBounds = false;
return BitmapFactory.decodeFile(orgImagePath, options);
}
public static int calculateInSampleSize(BitmapFactory.Options options,
int reqWidth, int reqHeight) {
final int height = options.outHeight;
final int width = options.outWidth;
int inSampleSize = 1;
if (height > reqHeight || width > reqWidth) {
if (width > height) {
inSampleSize = Math.round((float) height / (float) reqHeight);
} else {
inSampleSize = Math.round((float) width / (float) reqWidth);
}
}
return inSampleSize;
}
并且 decodeSampledBitmapFromResource 方法已从链接复制并将压缩图像设置为 intoimageview。