我正在使用这个广为人知的代码
Display display = this.getWindowManager().getDefaultDisplay();
float dw = display.getWidth();
float dh = display.getHeight();
// load image dimensions, not the image itself
BitmapFactory.Options bmpFactoryOptions = new BitmapFactory.Options();
bmpFactoryOptions.inJustDecodeBounds = true;
Bitmap bmp = BitmapFactory.decodeFile(MyApp.getImageFilePath());
int heightRatio = (int) FloatMath.ceil(bmpFactoryOptions.outHeight / dh);
int widthRatio = (int) FloatMath.ceil(bmpFactoryOptions.outWidth / dw);
if ((heightRatio > 1) && (widthRatio > 1))// if true one side of the image is bigger than the screen
{
if (heightRatio > widthRatio) {
bmpFactoryOptions.inSampleSize = heightRatio;
} else {
bmpFactoryOptions.inSampleSize = widthRatio;
}
}
// decode it for real
bmpFactoryOptions.inSampleSize = bmpFactoryOptions.inSampleSize;
bmpFactoryOptions.inPreferredConfig = Bitmap.Config.ARGB_8888; //http://www.curious-creature.org/2010/12/08/bitmap-quality-banding-and-dithering/
bmpFactoryOptions.inJustDecodeBounds = false;
bmpFactoryOptions.inDither = true;
bmp = BitmapFactory.decodeFile(MyApp.getImageFilePath(), bmpFactoryOptions);
ImageView photo = (ImageView) this.findViewById(R.id.imageView1);
问题是
bmpFactoryOptions.outWidth
bmpFactoryOptions.outHeight
bmpFactoryOptions.inSampleSize
永远有价值0
。我已经在三种不同的设备上对其进行了测试,我做错了什么?
和设置
bmpFactoryOptions.inSampleSize = bmpFactoryOptions.inSampleSize + 1;
没有效果