我使用這種被廣泛知道代碼安卓BitmapFactory總是返回0
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;
沒有效果
這是什麼'MyApp'? – codeKiller