最近,我发现渲染脚本是 Android 上图像处理的更好选择。表演很精彩。但关于它的文献并不多。我想知道是否可以通过渲染脚本将多张照片合并为结果照片。
http://developer.android.com/guide/topics/renderscript/compute.html http://developer.android.com/guide/topics/renderscript/compute.html says:
内核可能有一个输入Allocation
,输出Allocation
, 或两者。一个内核不能有超过一个输入或一个输出Allocation
。如果需要多个输入或输出,则应将这些对象绑定到rs_allocation
脚本全局变量并通过内核或可调用函数访问rsGetElementAt_type()
or rsSetElementAt_type()
.
这个问题有代码示例吗?
对于具有多个输入的内核,您必须手动处理其他输入。
假设您需要 2 个输入。
示例.rs:
rs_allocation extra_alloc;
uchar4 __attribute__((kernel)) kernel(uchar4 i1, uint32_t x, uint32_t y)
{
// Manually getting current element from the extra input
uchar4 i2 = rsGetElementAt_uchar4(extra_alloc, x, y);
// Now process i1 and i2 and generate out
uchar4 out = ...;
return out;
}
Java:
Bitmap bitmapIn = ...;
Bitmap bitmapInExtra = ...;
Bitmap bitmapOut = Bitmap.createBitmap(bitmapIn.getWidth(),
bitmapIn.getHeight(), bitmapIn.getConfig());
RenderScript rs = RenderScript.create(this);
ScriptC_example script = new ScriptC_example(rs);
Allocation inAllocation = Allocation.createFromBitmap(rs, bitmapIn);
Allocation inAllocationExtra = Allocation.createFromBitmap(rs, bitmapInExtra);
Allocation outAllocation = Allocation.createFromBitmap(rs, bitmapOut);
// Execute this kernel on two inputs
script.set_extra_alloc(inAllocationExtra);
script.forEach_kernel(inAllocation, outAllocation);
// Get the data back into bitmap
outAllocation.copyTo(bitmapOut);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)