Android:ScriptIntrinsicBlur错误

时间:2016-02-20 15:00:07

标签: android blur renderscript

我希望模糊到ImageView

此代码不起作用且ScriptIntrinsicBlur线强关闭

  

模糊课程:

private static final float BLUR_RADIUS = 20f;


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

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

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

设置模糊代码:

bmp = BitmapFactory.decodeStream(urlImage.openConnection().getInputStream());
bmp = blur(bmp);
imgPost.setImageBitmap(bmp);
  

和错误日志:

http://i.stack.imgur.com/sL2BT.jpg

1 个答案:

答案 0 :(得分:0)

根据ScriptIntrinsicBlur documentation,该类已在API 17中添加,因此在此之前不存在。您可以使用Renderscript Support Library获取访问Renderscript的API 8,包括android.support.v8.renderscript.ScriptIntrinsicBlur