我想使用以下 RenderScript 代码计算位图的像素
渲染脚本
文件名:counter.rs
#pragma version(1)
#pragma rs java_package_name(com.mypackage)
#pragma rs_fp_relaxed
uint count; // initialized in Java
void countPixels(uchar4* unused, uint x, uint y) {
rsAtomicInc(&count);
}
爪哇
Application context = ...; // The application context
RenderScript rs = RenderScript.create(applicationContext);
Bitmap bitmap = ...; // A random bitmap
Allocation allocation = Allocation.createFromBitmap(rs, bitmap);
ScriptC_Counter script = new ScriptC_Counter(rs);
script.set_count(0);
script.forEach_countPixels(allocation);
allocation.syncAll(Allocation.USAGE_SCRIPT);
long count = script.get_count();
错误
这是我收到的错误消息:
错误:找不到计数的地址
问题
- 为什么我的代码不起作用?
- 我该如何解决?