工具栏:
#main_bar {
background: url(../images/logo.jpg) 99% 50% no-repeat;
background-size: auto 80%;
}
logo.jpg 原始尺寸 220x266px
工具栏的高度为46px
所以背景图片的高度约为36px
工具栏在所有页面上都是一样的(一共2页)
我的问题是: 应用程序启动时图像看起来很完美。当我转到第二页时,它变得模糊。当我返回第一页时,它仍然很模糊。
如果改为
background-size: auto 36px;
问题依旧
有什么建议吗?
谢谢, 伊琳娜
最佳答案
公共(public)位图 resizeBitMapImage1(字符串文件路径,int targetWidth,int targetHeight) {
Bitmap bitMapImage = null;
Options options = new Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(filePath, options);
double sampleSize = 0;
Boolean scaleByHeight = Math.abs(options.outHeight - targetHeight) >= Math
.abs(options.outWidth - targetWidth);
if (options.outHeight * options.outWidth * 2 >= 1638) {
sampleSize = scaleByHeight ? options.outHeight / targetHeight
: options.outWidth / targetWidth;
sampleSize = (int) Math.pow(2d,
Math.floor(Math.log(sampleSize) / Math.log(2d)));
}
options.inJustDecodeBounds = false;
options.inTempStorage = new byte[128];
while (true) {
try {
options.inSampleSize = (int) sampleSize;
bitMapImage = BitmapFactory.decodeFile(filePath, options);
break;
} catch (Exception ex) {
try {
sampleSize = sampleSize * 2;
} catch (Exception ex1) {
}
}
}
return bitMapImage;
}
关于android:第二页上调整后的图像模糊,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21255923/