1

我正在尝试对图像视图中显示的图像创建模糊效果。我遇到了一个例子,说明缩小位图中的图像然后再次放大它(我认为是双线性过滤),到目前为止图像质量真的很差。我试图实现一个很好的平滑模糊。我目前使用的代码是:

originalImage = BitmapFactory.decodeResource(getResources(),
            mImageIds[coverFlow.getSelectedItemPosition()]);

    xPos = originalImage.getWidth() / 2;

    zoomedImage = Bitmap.createBitmap(originalImage, xPos / 2, yPos, width,
            height);

    int upWidth = (int) (width * 3.5); //width is 450 >> upWidth is 1575
    int upHeight = (int) (height * 3.5); //height is 700 >> upHeight is 2450

    int downWidth = (int) ((width * 1.75)*0.06); //width is 450 >> downWidth is 787.5
    int downHeight = (int) ((height * 1.75)*0.06); //height is 700 >> downHeight is 1225

    Bitmap ScaledUp = Bitmap.createScaledBitmap(zoomedImage, upWidth,
            upHeight, true);
    Bitmap BlurredImage = Bitmap.createScaledBitmap(ScaledUp, downWidth,
            downHeight, true);

    background.startAnimation(myFadeInAnimation);
    background.setImageBitmap(BlurredImage);
    background.setFocusable(true);

有人可以解释出了什么问题吗?我似乎无法获得平滑的模糊,它总是像素化。

4

1 回答 1

1

在我的脑海中,我会尝试以下方法:

//downscale Bitmap bmp = Bitmap.createScaledBitmap(originalBitmap, originalBitmap.getWidth()/scale, originalBitmap.getHeight()/scale, true); //blur Bitmap blurred = blurAlgorithm.blur(bmp, BLUR_RADIUS); //draw the blurred image Canvas c = new Canvas(blurred); //upscale c.scale(scale, scale);

对于 android 的一个好的模糊算法,看看这个。通常,该项目有很多关于如何正确进行模糊的信息。

于 2014-03-06T15:25:36.703 回答