我开发了一个应用程序,其目标是计算每列的灰度平均值。这是我的代码:
mInputAllocation=Allocation.createFromBitmap(mRs, mBitmapIn.MipMapControl.MIPMAP_NONE, allocation.USAGE_SCRIPT);
mOutputAllocation=Allocation.createSized(mRs, Element.I32, Allocation.USAGE_SCRIPT);
mScript.bind_gInPixels(mInputAllocation);
mScript.bind_gResult(mOutputAllocation);
mScript.invoke_filter();
在myscript.rs中我有:
int sum;
int32_t *gResult;
const uchar4 *gInPIxels;
void root(const uint32_t *v_in, int_32 *v_out, uint32_t x, uint32_t y){
for(int i=0;i<mImageWidth;i++){
sum=sum+gray;}
gResult[*v_out]=sum;}
void filter(){
rsForEach(gScript, gIn, gOut);}
我在手机上执行应用程序时出现此异常: API20 +仅允许简单的1D分配与bind一起使用。
答案 0 :(得分:0)
我肯定错过了myscript.rs的东西,因为我看到了对“灰色”的引用,但没有实际的定义。您似乎也使用* v_out作为索引,但这实际上不是它的目的。就访问不同x / y坐标的数据而言,最好使用rsSetElementAt_int()。在http://developer.android.com/guide/topics/renderscript/reference/rs_allocation_data.html#android_rs:rsSetElementAt中查看该功能。