我用这种方式创建了类型化的RS分配:
mRS = RenderScript.create(mContext);
Element.Builder eb = new Element.Builder(mRS);
eb.add(Element.F32_3(mRS), "xyz");
eb.add(Element.F32_2(mRS), "uv");
Element eStride_XYZUV = eb.create();
mInAllocation = Allocation.createSized(mRS, eStride_XYZUV, animLand.getArray().length / 5);
mOutAllocation = Allocation.createSized(mRS, eStride_XYZUV, animLand.getArray().length / 5);
animLand.getArray()
是float
的数组。我可以将数据复制到输入分配:
mInAllocation.copyFromUnchecked(animLand.getArray());
但是,当我尝试以这种方式从分配中检索数据时:
mOutAllocation.copyTo(animLand.getArray());
我得到例外:
android.renderscript.RSIllegalArgumentException: 32 bit float source does not match allocation type null
如何使用自定义Allocation
数组从输出Element
访问数据?有方法可以复制到数组/位图,但只能用于原始Element
类型。
如果我使用原始F32
类型但我想使用类型数据
mInAllocation = Allocation.createSized(mRS, Element.F32(mRS), animLand.getArray().length);
mOutAllocation = Allocation.createSized(mRS, Element.F32(mRS), animLand.getArray().length);
...
mInAllocation.copyFromUnchecked(animLand.getArray());
...
mOutAllocation.copyTo(animLand.getArray());