2016-04-14 12 views
0

Projemde bulanık arka plan kullanmak istiyorum. Aşağıdaki yöntemi kullandığımda arka plan bulanıklaşıyor, ancak bu benim için yeterince bulanık değil, daha bulanık arka plan yapmak istiyorum. maksimum değeri olarak yarıçapı 25.Birisi bana yardımcı olabilir? 25 bir bulanıklık yarıçapı kullanmayan hala yeterince iseAndroid'de RenderScript ile Daha Fazla Bulanıklık

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; 


} 

cevap

0

, bulanıklık yapmanın bir ucuz yolu aşağı arka plan resmi yeniden boyutlandırmak ve daha sonra yukarı boyutlandırmak etmektir.

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

BITMAP_SCALE 0.3f gibi azalan Miao'ya teşekkürler, görüntüm çok bulanık. – nihasmata

+0

Evet, bunu yeniden boyutlandırmak ile aynı şeyi yapıyor. BITMAP_SCALE ve RenderScript Resize ile performansın düştüğünü ve kalitesini karşılaştırdığınızı merak ediyorum. –

+0

Hayır Miao, çözümünüzü 1.f/5.f yeniden boyutlandırma ölçeği ile denedim, çok bulanık olmadı. Hiçbir şey değişmedi :) – nihasmata