2016-04-14 6 views
0

私のプロジェクトでは、ぼやけた背景を使用したいと思います。次の方法を使用すると、背景がぼやけますが、十分にぼやけていないため、背景がぼやけます。半径は最大値25です。誰かが私を助けることができますか?さらにぼやけたRenderScript with Android

private static final float BITMAP_SCALE = 0.9f; 
private static final float BLUR_RADIUS = 25.0f; 

public static Bitmap blur(Context context, Bitmap image) { 
    int width = Math.round(image.getWidth() * BITMAP_SCALE); 
    int height = Math.round(image.getHeight() * BITMAP_SCALE); 

    Bitmap inputBitmap = Bitmap.createScaledBitmap(image, width, height, false); 
    Bitmap outputBitmap = Bitmap.createBitmap(inputBitmap); 

    RenderScript rs = RenderScript.create(context); 
    ScriptIntrinsicBlur theIntrinsic = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs)); 
    Allocation tmpIn = Allocation.createFromBitmap(rs, inputBitmap); 
    Allocation tmpOut = Allocation.createFromBitmap(rs, outputBitmap); 
    theIntrinsic.setRadius(BLUR_RADIUS); 
    theIntrinsic.setInput(tmpIn); 
    theIntrinsic.forEach(tmpOut); 
    tmpOut.copyTo(outputBitmap); 

    return outputBitmap; 


} 

答えて

0

25のぼかし半径を使用すると、まだ十分でない場合は、ぼかしを行うには1安価な方法は、下の背景画像のサイズを変更し、それをアップサイズを変更することです。

private static final float BITMAP_SCALE = 0.9f; 
private static final float RESIZE_SCALE = 1.f/5.f; 
private static RenderScript rs; 

public static Bitmap blur(Context context, Bitmap image) { 
    int width = Math.round(image.getWidth() * BITMAP_SCALE); 
    int height = Math.round(image.getHeight() * BITMAP_SCALE); 

    Bitmap inputBitmap = Bitmap.createScaledBitmap(image, width, height, false); 
    Bitmap outputBitmap = Bitmap.createBitmap(inputBitmap); 

    if (rs == null) { 
     // Creating a RS context is expensive, better reuse it. 
     rs = RenderScript.create(context); 
    } 
    Allocation tmpIn = Allocation.createFromBitmap(rs, inputBitmap); 
    Allocation tmpOut = Allocation.createFromBitmap(rs, outputBitmap); 

    Type t = Type.createXY(mRS, tmpIn.getElement(), width*RESIZE_SCALE, height*RESIZE_SCALE); 
    Allocation tmpScratch = Allocation.createTyped(rs, t); 

    ScriptIntrinsicResize theIntrinsic = ScriptIntrinsicResize.create(rs); 
    // Resize the original img down. 
    theIntrinsic.setInput(tmpIn); 
    theIntrinsic.forEach_bicubic(tmpScratch); 
    // Resize smaller img up. 
    theIntrinsic.setInput(tmpScratch); 
    theIntrinsic.forEach_bicubic(tmpOut); 
    tmpOut.copyTo(outputBitmap); 

    return outputBitmap; 
} 
+0

ミアオさん、0.3fのようにBITMAP_SCALEを減らしてくれてありがとうございました。 – nihasmata

+0

ええ、それはサイズを変更するのと同じことをやっています。 BITMAP_SCALEが低下するパフォーマンスと品質を比較した場合、RenderScript Resizeと比較しても不思議です。 –

+0

No Miao、私は1.f/5.fサイズスケールであなたのソリューションを試しました、それはあまりぼやけませんでした。何も変更されていません:) – nihasmata

関連する問題