android – 如何使用具有多个输入分配的RenderScript?
作者:互联网
最近,我发现渲染脚本是Android上图像处理的更好选择.表演很精彩.但是关于它的文件并不多.我想知道我是否可以通过渲染脚本将多张照片合并到结果照片中.
http://developer.android.com/guide/topics/renderscript/compute.html说:
A kernel may have an input
Allocation
, an outputAllocation
, or both. A kernel may not have more than one input or one outputAllocation
. If more than one input or output is required, those objects should be bound tors_allocation
script globals and accessed from a kernel or invokable function viarsGetElementAt_type()
orrsSetElementAt_type()
.
这个问题有代码示例吗?
解决方法:
对于具有多个输入的内核,您必须手动处理其他输入.
假设您想要2个输入.
example.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);
标签:android,renderscript 来源: https://codeday.me/bug/20190831/1773974.html