两个位图中的模糊图像

时间:2017-02-26 17:43:09

标签: android image bitmap android-imageview

您好我的图像模糊有问题..

我想在一个Imageview中设置模糊背景和原始图像..

我尝试把所有的一个imageview ..现在我测试两个imageview但它是相同的..

我的代码

// 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代码模糊效果,除了这一行theIntrinsic.forEach(tmpOut);上的任何内容都是位图imageenter code here中的模糊图像我不知道知道为什么......

在完成此操作后,方法模糊图像位于bluredBitmapbitmap,但这是错误的..

请帮帮我

1 个答案:

答案 0 :(得分: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);