Bitmap二次采样(处理图片过大的问题)

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;

}

posted @ 2016-05-08 19:11  黑色秋梨膏  阅读(636)  评论(0编辑  收藏  举报