私はこの広く知られているコードを使用しています
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
。3つの異なるデバイスでテストしましたが、何が間違っていますか?
と設定
bmpFactoryOptions.inSampleSize = bmpFactoryOptions.inSampleSize + 1;
効果はありません