android:在第二页上调整大小的图像模糊

时间:2014-01-21 10:49:12

标签: android css resize background-image

工具栏:

#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;

问题仍然存在

有什么建议吗?

谢谢你, 伊琳娜

1 个答案:

答案 0 :(得分:0)

public Bitmap resizeBitMapImage1(String filePath,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;
    }