Androidx RenderScript没有运行android api <19

问题描述 投票:1回答:2

我有使用androidx与模糊图像,但运行android api <19崩溃的应用程序。当我运行android> 19时,我运行正常,而不是崩溃应用程序,如果我使用Android正常与“android.support.v8.renderscript”没有崩溃的应用程序。在build.gradle。我补充说:

  renderscriptTargetApi 18
    renderscriptSupportModeEnabled true

代码应用:

public static Bitmap blurBitmap(Bitmap bitmap,
                                float radius) {        //Create renderscript
    RenderScript
            rs = RenderScript.create(MyApplication.getInstance());

    //Create allocation from Bitmap
    Allocation allocation = Allocation.createFromBitmap(rs,
            bitmap);
    Type t = allocation.getType();

    //Create allocation with the same type
    Allocation blurredAllocation = Allocation.createTyped(rs,
            t);

    //Create script
    ScriptIntrinsicBlur blurScript = ScriptIntrinsicBlur.create(rs, Element.U8(rs));

    //Set blur radius (maximum 25.0)
    blurScript.setRadius(radius);
    //Set input for script
    blurScript.setInput(allocation);
    //Call script for output allocation
    blurScript.forEach(blurredAllocation);

    //Copy script result into bitmap
    blurredAllocation.copyTo(bitmap);

    //Destroy everything to free memory
    allocation.destroy();
    blurredAllocation.destroy();
    blurScript.destroy();
    t.destroy();
    rs.destroy();
    return bitmap;
}
renderscript
2个回答
1
投票

这与您的实施无关。这是androidx库中的一个错误,事实上,即使在API 21上它也会发生,所以它可能比你经历的影响更大。

有人已经提交了here问题。我一直在关注这个问题很长一段时间,遗憾的是没有太多进展。对于我来说,这对于我的许多项目来说都是迁移到AndroidX的一个障碍。


0
投票

Element.U8ScriptIntrinsicBlur.create()论证是不正确的。

ScriptIntrinsicBlur期待AllocationElement.U8类型的元素,但Bitmap支持Allocation有元素类型Element.RGBA_8888(a.k.a Element.U8_4)。

尝试:

ScriptIntrinsicBlur.create(rs, Element.RGBA_8888(rs))

或者一般来说:

ScriptIntrinsicBlur.create(rs, allocation.getElement()) 
© www.soinside.com 2019 - 2024. All rights reserved.