2017-02-26 68 views
0

你好,我有模糊圖像的問題..模糊圖像的兩個位圖

我想在一個ImageView的設置模糊的背景和原始圖像..

我嘗試把所有的一個imageview的..現在我梅索德模糊後測試兩個imageviews但它是相同的..

我的代碼

// Then later, when you want to display image 
    ImageLoader.getInstance().displayImage(listKone.get(i).getCestaObrazok(), imgHorse); // Default options will be used 

// ↑ thise method have link where are my image and download image and show it in imgHorse ImageView 

     imgHorseB=imgHorse; 


    ImageLoader.getInstance().displayImage(listKone.get(i).getCestaObrazok(), imgHorseB); // Default options will be used 
    BitmapDrawable drawable = (BitmapDrawable) imgHorseB.getDrawable(); 
    Bitmap bitmap = drawable.getBitmap(); 

    Bitmap blurredBitmap = blur(bitmap); 
    imgHorseB.setImageBitmap(blurredBitmap); 





    public Bitmap blur(final Bitmap image) { 
     if (null == image) return null; 

     Bitmap outputBitmap = Bitmap.createBitmap(image); 
     final RenderScript renderScript = RenderScript.create(activity); 
     Allocation tmpIn = Allocation.createFromBitmap(renderScript, outputBitmap); 
     Allocation tmpOut = Allocation.createFromBitmap(renderScript, outputBitmap); 

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

有blure圖像中的所有的位圖。如果debbug代碼模糊效果,不過對thise行theIntrinsic.forEach(tmpOut);在兩個位圖模糊圖像imageenter code here我不知道爲什麼..

並完成後thise梅索德模糊圖像是bluredBitmapbitmap但它是錯的..

請幫我

回答

0
@SuppressLint("NewApi") 
public static Bitmap blurRenderScript(Context context,Bitmap smallBitmap, int radius) { 
    try { 
     smallBitmap = RGB565toARGB888(smallBitmap); 
    } catch (Exception e) { 
     e.printStackTrace(); 
    } 

    Bitmap bitmap = Bitmap.createBitmap(
      smallBitmap.getWidth(), smallBitmap.getHeight(), 
      Bitmap.Config.ARGB_8888); 

    RenderScript renderScript = RenderScript.create(context); 

    Allocation blurInput = Allocation.createFromBitmap(renderScript, smallBitmap); 
    Allocation blurOutput = Allocation.createFromBitmap(renderScript, bitmap); 

    ScriptIntrinsicBlur blur = ScriptIntrinsicBlur.create(renderScript, 
      Element.U8_4(renderScript)); 
    blur.setInput(blurInput); 
    blur.setRadius(radius); // radius must be 0 < r <= 25 
    blur.forEach(blurOutput); 

    blurOutput.copyTo(bitmap); 
    renderScript.destroy(); 

    return bitmap; 

} 


    Bitmap blurred = blurRenderScript(activity,bitmap, 25); 
//second parametre is radius 
     imgHorseB.setScaleType(ImageView.ScaleType.FIT_XY); 
     imgHorseB.setImageBitmap(blurred);