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

标签 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);

最佳答案

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

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

关于android - 在同一位图上应用两个或多个 ScriptIntrinsicConvolve3x3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50745687/

相关文章:

android - 不同设备上的 openGL ES 版本

java - Android Studio 模拟器不工作

java - 身份验证问题..!!在 Android 上使用 HTTPURLCONNECTION

android - "You need to use a Theme.AppCompat theme (or descendant) with the design library"错误

java - 设置 XY 图上点标签的格式

android - 如何查询两个日期之间的内容解析器?

Android 动态文字绘制/触摸检测

android - 更改 TextView 颜色

java - 为什么 android logcat 不显示运行时异常的堆栈跟踪?

android - 为 arm64 Android 手机构建应用程序包时,在 ApplicationInfo.nativeLibraryDir 中找不到 native 库