2016-11-26 106 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);