private Bitmap createImageThumbnail(String filePath, int newHeight,
int newWidth) {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(filePath, options);
int oldHeight = options.outHeight;
int oldWidth = options.outWidth;
// Log.i(TAG, "高度是:" + oldHeight + ",宽度是:" + oldWidth);
int ratioHeight = oldHeight / newHeight;
int ratioWidth = oldWidth / newWidth;
options.inSampleSize = ratioHeight > ratioWidth ? ratioWidth
: ratioHeight;
options.inPreferredConfig = Config.RGB_565;
options.inJustDecodeBounds = false;
Bitmap bm = BitmapFactory.decodeFile(filePath, options);
// Log.i(TAG, "高度是:" + options.outHeight + ",宽度是:" + options.outWidth);
return bm;
}
时间: 2024-10-13 16:31:35