Skip to content

Instantly share code, notes, and snippets.

@duanhong169
Last active December 15, 2015 08:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save duanhong169/5235223 to your computer and use it in GitHub Desktop.
Save duanhong169/5235223 to your computer and use it in GitHub Desktop.
public static Bitmap decodeSampledBitmapFromDescriptor(
FileDescriptor fileDescriptor, int reqWidth,
int reqHeight, ImageCache cache) {
// 设置inJustDecodeBounds=true来获取图片的尺寸
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFileDescriptor(fileDescriptor, null, options);
// 计算采样率
options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);
// 设置inJustDecodeBounds=false得到bitmap对象
options.inJustDecodeBounds = false;
return BitmapFactory.decodeFileDescriptor(fileDescriptor, null, options);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment