Android   发布时间:2022-04-28  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了如何让Android Render Script Group工作?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

我可以让两个独立的内在函数工作,但不能在ScriptGroup中一起工作.我发现有关如何使用Script Group的文档非常稀疏.

这是我的代码

        mRS = RenderScript.create(getActivity());

        mInAlLOCATIOn = AlLOCATIOn.createFromBitmap(mRS,mBitmapIn,AlLOCATIOn.MipmapControl.MIPMAP_NONE,AlLOCATIOn.USAGE_SCRIPT |
                        AlLOCATIOn.USAGE_GRAPHICS_TEXTURE|
                        AlLOCATIOn.USAGE_SHARED
        );

        mOutAlLOCATIOn = AlLOCATIOn.createFromBitmap(mRS,mBitmapOut,AlLOCATIOn.USAGE_SCRIPT |
                        AlLOCATIOn.USAGE_SHARED);

        ScripTintrinsicColorMatrix gray = ScripTintrinsicColorMatrix.create(mRS,Element.U8_4(mRS));
        gray.setGreyscale();


        ScripTintrinsicBlur blur = ScripTintrinsicBlur.create(mRS,Element.U8_4(mRS));
        blur.seTradius(20.f);
        blur.seTinput(mInAlLOCATIOn);

        //gray.forEach(mInAlLOCATIOn,mOutAlLOCATIOn);
        blur.forEach(mOutAlLOCATIOn);

        mOutAlLOCATIOn.copyTo(mBitmapOut);

灰色和模糊都有效.然后我尝试将它们放在一起,结果是空白的.码:

       // gray.forEach(mInAlLOCATIOn,mOutAlLOCATIOn);
       // blur.forEach(mOutAlLOCATIOn);
       // mOutAlLOCATIOn.copyTo(mBitmapOut);

        ScriptGroup.builder builder = new ScriptGroup.builder(mRS);

        builder.addKernel(gray.getKernelID());
        builder.addKernel(blur.getKernelID());

        builder.addConnection(mInAlLOCATIOn.getType(),gray.getKernelID(),blur.getKernelID());

        ScriptGroup group = builder.create();

        group.seTinput(gray.getKernelID(),mInAlLOCATIOn);
        group.setOutput(blur.getKernelID(),mOutAlLOCATIOn);

        group.execute();

        mOutAlLOCATIOn.copyTo(mBitmapOut);
最佳答案
我能够重现您所看到的问题,并使用我之前使用内在函数的实验中的注释进行交叉检查.我认为renderscript内在函数代码中存在一些错误.

-1-
如果您希望使用内在函数的脚本组,则以下序列有效.

@H_295_7@mBlur.seTinput(mInAlLOCATIOn);
sBuilder = new ScriptGroup.builder(mRS);
sBuilder.addKernel(mBlur.getKernelID());
sBuilder.addKernel(mColor.getKernelID());
sBuilder.addConnection(connect,mBlur.getKernelID(),mColor.getKernelID());

sGroup = sBuilder.create();
//  sGroup.seTinput(mBlur.getKernelID(),mInAlLOCATIOn); //See point 2
sGroup.setOutput(mColor.getKernelID(),mOutAlLOCATIOn);
sGroup.execute();

mOutAlLOCATIOn.copyTo(outBitmap);
mRs.finish();

-2-
请注意输入分配的传递方式.输入分配传递给mBlur.setinput()而不传递给sGroup.setinput().如果使用了sGroup.setinput(),那么该组正确地找不到输入,并且它会导致以下错误和当然,我也不会在屏幕上看到转换后的图像.

E/RenderScript(12023): rsAssert Failed: !"ScriptGroup:seTinput kid not found",in frameworks/rs/@L_944_13@criptGroup.cpp at 267

在-1-的这个具体示例中,我在使用sGroup.setinput()而不是mBlur.setinput()时获得了以下错误

E/RenderScript(12023): Blur executed without input,skipping

这似乎是renderscript中的bug

-3-
具体来说,在您的情况下,您希望在序列中使用ScripTintrinsicBlur执行ScripTintrinsicColorMatrix,还有另一个问题(不一定是错误).然Blur内部有一个seTinput函数,但colorMatrix确实有一个seTinput函数.因此,您也不能使用-1-作为解决方法.

-4-
我认为renderscript中的正确修复将是弃用
intrinsic.seTinput与ScripTintrinsicColorMatrix一样普遍,并且在脚本组中使用intrinsics时可以使ScriptGroup.seTinput正常工作.

-5-
当我拥有自己的内核时,我没有看到使用scriptgroup的任何问题.换句话说,scriptGroup.setinput()和scriptGroup.setOutput()完全正常

大佬总结

以上是大佬教程为你收集整理的如何让Android Render Script Group工作?全部内容,希望文章能够帮你解决如何让Android Render Script Group工作?所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。