在同一位图上应用两个或多个ScriptIntrinsicConvolve3x3

时间:2018-06-07 16:02:22

标签: android

当应用多个过滤器时,ScriptIntrinsicConvolve3x3出现了一个小问题。当我应用过滤器(B)时,它会覆盖过滤器(A)。我想知道是否可以使用ScriptIntrinsicConvolve3x3来实现它?谢谢!

mRS = android.renderscript.RenderScript.create( app.android.context );
    mInAllocation  = android.renderscript.Allocation.createFromBitmap(mRS, bitmap, android.renderscript.Allocation.MipmapControl.MIPMAP_NONE, android.renderscript.Allocation.USAGE_SCRIPT);
    mOutAllocation = android.renderscript.Allocation.createTyped(mRS, mInAllocation.getType());


    //A - First Filter
    let a = android.renderscript.ScriptIntrinsicConvolve3x3.create(mRS, android.renderscript.Element.U8_4(mRS));
    a.setInput(mInAllocation);
    a.setCoefficients(toFloatArray([-2, -1, -0, -1, 1, 1, 0, 1, 2]));
    a.forEach(mOutAllocation);
    mOutAllocation.copyTo(this.image.bitmap._nativeObject);
    //B - Second Filter
    let b = android.renderscript.ScriptIntrinsicConvolve3x3.create(mRS, android.renderscript.Element.U8_4(mRS));
    b.setInput(mInAllocation);
    b.setCoefficients(toFloatArray([-1, -1, -1, -1,  1, -1, -1, -1, -1]));
    b.forEach(mOutAllocation);
    mOutAllocation.copyTo(this.image.bitmap._nativeObject);

1 个答案:

答案 0 :(得分:1)

我认为你应该使用A的输出B:

let a = android.renderscript.ScriptIntrinsicConvolve3x3.create(mRS, android.renderscript.Element.U8_4(mRS));
a.setInput(mOutAllocation); // fix here