2016-11-26 16 views
0

編輯:我發現了一個解決方案。儘管它更奇怪的解決方法。答案在下面。模糊函數(ScriptIntrinsicBlur)被施加到模糊多個位圖比希望

我有一個位圖的兩個副本。其中一個變得模糊和放大。另一個應該保持原來的樣子,但有些東西會對它施加相同的模糊。我不太確定問題在哪。

public static Bitmap blur(Bitmap image, float radius, int runs, Context context) { 
    if (null == image) return null; 

    Bitmap outputBitmap = Bitmap.createBitmap(image); 
    final RenderScript renderScript = RenderScript.create(context); 

    for (int x = 0; x < runs; x++) { 
     Allocation tmpIn = Allocation.createFromBitmap(renderScript, image); 
     Allocation tmpOut = Allocation.createFromBitmap(renderScript, outputBitmap); 

     //Intrinsic Gausian blur filter 
     ScriptIntrinsicBlur theIntrinsic = ScriptIntrinsicBlur.create(renderScript, Element.U8_4(renderScript)); 
     theIntrinsic.setRadius(radius); 
     theIntrinsic.setInput(tmpIn); 
     theIntrinsic.forEach(tmpOut); 
     tmpOut.copyTo(outputBitmap); 
    } 
    return outputBitmap; 
} 

這裏是我使用此功能: 位圖是一個,那是應該保持不變,但它得到模糊的。

   bitmapS = bitmap; 
       bitmapHeight = bitmap.getHeight(); 
       bitmapWidth = bitmap.getWidth(); 

       int scale = Math.round((screenHeight/bitmapHeight) + 0.5f); 
       bitmapL = bitmap; 
       bitmapL = blur(bitmapL, 25f, 3, WallpaperService.this); 
       bitmapL = blur(
         Bitmap.createScaledBitmap(bitmapL 
           , bitmapWidth * scale, bitmapHeight * scale, true), 
         25f, 1, WallpaperService.this); 
+0

允許Bitmap.CreateBitmap()返回原始位圖。您可以嘗試Bitmap.copy()方法。 – sakridge

回答

0

我仍然不知道是什麼導致了這個問題,但我找到了解決方法。

因爲我想模糊圖像更無論哪種方式,我只是縮放的位圖下來,模糊了它。之後我又把它放大了。縮放似乎以某種方式解決了我的問題。

bitmapL = Bitmap.createScaledBitmap(bitmap, bitmapWidth/3, bitmapHeight/3, true); 
bitmapL = blur(bitmapL, 25f, 2, WallpaperService.this); 
bitmapL = blur(Bitmap.createScaledBitmap(
    bitmapL, bitmapWidth * scaleL, bitmapHeight * scaleL, true), 
    25f, 1, WallpaperService.this);