2016-11-26 4 views
0

EDIT:解決策が見つかりました。それは変わった回避策ではありますが。答えは下にあります。ぼかし関数(ScriptIntrinsicBlur)は、必要以上のビットマップにブラーを適用しています

私は2つのビットマップのコピーを持っています。それらの1つがぼやけて拡大します。もう一方はもともとのままであると考えられていますが、何かがそれに同じぼかしを適用しています。私はその問題が何であるかについてはあまりよく分かりません。

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

そして、ここで私は、この機能を使用する場所である: ビットマップは、それは同じままになっています、1であるが、それは同様にぼやけます。

   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); 
関連する問題