Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/187.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
ANDROID-将组renderscript输出分配转换为位图_Android_Renderscript - Fatal编程技术网

ANDROID-将组renderscript输出分配转换为位图

ANDROID-将组renderscript输出分配转换为位图,android,renderscript,Android,Renderscript,下面的组renderscript输入是位图,输出也应该是位图。但将输出分配转换为位图时,会发生错误: 07-16 20:24:36.650 9640 9724 E RenderScript_jni: non fatal RS error, Failed to launch kernel; dimensions of input and output allocations do not match. 07-16 20:24:36.651 9640 9640 W System.err: a

下面的组renderscript输入是位图,输出也应该是位图。但将输出分配转换为位图时,会发生错误:

07-16 20:24:36.650  9640  9724 E RenderScript_jni: non fatal RS error, Failed to launch kernel; dimensions of input and output allocations do not match.
07-16 20:24:36.651  9640  9640 W System.err: androidx.renderscript.RSIllegalArgumentException: Object passed is not an array of primitives.
07-16 20:24:36.652  9640  9640 W System.err:    at androidx.renderscript.Allocation.validateObjectIsPrimitiveArray(Allocation.java:87)
07-16 20:24:36.652  9640  9640 W System.err:    at androidx.renderscript.Allocation.copyFrom(Allocation.java:834)
07-16 20:24:36.652  9640  9640 W System.err:    at com.sample.groupScriptDemo(MainActivity.java:380)
代码:


如何将分配对象转换为位图?

groupscript api已更改,请参阅api文档
private void groupScriptDemo() {
    Bitmap src = BitmapFactory.decodeResource(getResources(),R.drawable.lena);
    Bitmap result = Bitmap.createBitmap(src.getWidth(), src.getHeight(), Bitmap.Config.ARGB_8888);

    RenderScript rs = RenderScript.create(this);
    Allocation inAlloc = Allocation.createFromBitmap(rs, src,
            Allocation.MipmapControl.MIPMAP_NONE,
            Allocation.USAGE_SCRIPT |
                    Allocation.USAGE_GRAPHICS_TEXTURE|
                    Allocation.USAGE_SHARED
    );

    ScriptIntrinsicBlur blur = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
    blur.setRadius(20.f);

    ScriptIntrinsicColorMatrix gray = ScriptIntrinsicColorMatrix.create(rs, Element.U8_4(rs));
    gray.setGreyscale();

    ScriptGroup.Builder2 builder = new ScriptGroup.Builder2(rs);
    ScriptGroup.Input unbound = builder.addInput();
    ScriptGroup.Closure cblur = builder.addKernel(
            blur.getKernelID(),
            Type.createX(rs,Element.U8_4(rs),src.getWidth()*src.getHeight()),unbound);
    ScriptGroup.Closure cgray = builder.addKernel(
            gray.getKernelID(),
            Type.createX(rs,Element.U8_4(rs),src.getWidth()*src.getHeight()), cblur.getReturn());

    ScriptGroup group = builder.create("groupscript_demo",cgray.getReturn());
    Object outObj = group.execute(inAlloc)[0];
    Allocation outAlloc = Allocation.createTyped(rs, inAlloc.getType());
    outAlloc.copyFrom(outObj);
    outAlloc.copyTo(result);

    inAlloc.destroy();
    outAlloc.destroy();
    group.destroy();
    rs.destroy();
    //showBitmap(this,src,ivInput);
    //showBitmap(this,result,ivOutput);
    return;
}