/**
* 生成缩略图
* 缩略图是将原图等比压缩,压缩后宽、高中较小的一个等于198像素
*/
private Bitmap getThumb(String path){final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(path, options);
int reqWidth, reqHeight, width=options.outWidth, height=options.outHeight;
if (width > height){reqWidth = 198;
reqHeight = (reqWidth * height)/width;
}else{reqHeight = 198;
reqWidth = (width * reqHeight)/height;
}int inSampleSize = 1;
if (height > reqHeight || width > reqWidth) {final int halfHeight = height / 2;
final int halfWidth = width / 2;
while ((halfHeight / inSampleSize) > reqHeight&& (halfWidth / inSampleSize) > reqWidth) {inSampleSize *= 2;
}}try{options.inSampleSize = inSampleSize;
options.inJustDecodeBounds = false;
Matrix mat = new Matrix();
Bitmap bitmap = BitmapFactory.decodeFile(path, options);
ExifInterface ei = new ExifInterface(path);
int orientation = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
switch(orientation) {case ExifInterface.ORIENTATION_ROTATE_90:mat.postRotate(90);
break;
case ExifInterface.ORIENTATION_ROTATE_180:mat.postRotate(180);
break;
}
// Log.e("test","bitmap.getWidth():"+bitmap.getWidth()+",,bitmap.getHeight():"+bitmap.getHeight());
return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), mat, true);
}catch (IOException e){return null;
}}
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!