无法在android中的imageview上创建位图模糊效果

时间:2013-01-15 14:03:33

标签: android bitmap imageview blur

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

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

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

1 个答案:

答案 0 :(得分:0)

在我的头顶,我会尝试以下内容:

//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的良好模糊算法,请查看this。 一般来说,该项目有很多关于如何正确模糊的信息。

相关问题