2013-01-15 150 views
0

我試圖在圖像視圖中顯示的圖像上創建模糊的效果。我遇到過一個例子,它將圖像縮小到位圖中,然後重新放大(我認爲是雙線性濾波),到目前爲止圖像質量非常差。我正試圖獲得一個很好的光滑模糊。我目前使用的代碼是:無法在android中的imageview上創建位圖模糊效果

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

有人可以解釋發生了什麼問題嗎?我似乎無法得到平滑的模糊,它總是像素化。

+0

你讀過這篇文章http://graphics-geek.blogspot.ru/2011/01/video-reflections-on-android.html? –

+0

我剛剛看了一下它的好處,但我試圖讓它變得模糊,並且似乎使它更透明。 –

+0

是的,但生成的圖像也是模糊的。看看'blurryBitmap'是如何創建然後模糊的 –

回答

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。 通常,該項目有很多關於如何正確模糊的信息。