Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android Renderscript:如何分配uchar4数组_Android_Arrays_Renderscript_Android Renderscript - Fatal编程技术网

Android Renderscript:如何分配uchar4数组

Android Renderscript:如何分配uchar4数组,android,arrays,renderscript,android-renderscript,Android,Arrays,Renderscript,Android Renderscript,在我的Android代码中,我保留了一组我希望在renderscript代码中使用的颜色,如下所示: for(int col = 0; col < imgWidth; col++){ const uchar4 colour = *(const uchar4*)rsGetElementAt(colours, col, 0); if (in.r == colour.r && in.g == colour.g && in.b == colour.b

在我的Android代码中,我保留了一组我希望在renderscript代码中使用的颜色,如下所示:

for(int col = 0; col < imgWidth; col++){
   const uchar4 colour = *(const uchar4*)rsGetElementAt(colours, col, 0);
     if (in.r == colour.r && in.g == colour.g && in.b == colour.b){
        in.r = 255;
        in.g = 0;
        in.b = 0;
        break;
    } else {
       in.r = 0;
       in.g = 255;
       in.b = 0;
    }

}
return in;
在java中,我有:

Bitmap.Config conf = Bitmap.Config.ARGB_8888; // see other conf types
Bitmap myBitmap = Bitmap.createBitmap(pickedPanels.size(), 1, conf);
myBitmap.setPixels(myInts, 0, myBitmap.getWidth(), 0, 0, myBitmap.getWidth(),0);

final RenderScript rs = RenderScript.create(this);

// The input image.
final Allocation input = Allocation.createFromBitmap(rs, bitmap, Allocation.MipmapControl.MIPMAP_NONE,
Allocation.USAGE_SCRIPT);

// The output image.
final Allocation output = Allocation.createTyped(rs, input.getType());
        final ScriptC_singlesource script = new 

ScriptC_singlesource(rs);

// The array of colours.
final Allocation pixels = Allocation.createFromBitmap(rs, myBitmap, Allocation.MipmapControl.MIPMAP_NONE,
                Allocation.USAGE_SCRIPT);
script.set_image(pixels);
script.set_imgWidth(pickedPanels.size());
script.forEach_root(input, output);
// retrieve output
output.copyTo(bitmap);

        ImageView destim = (ImageView) findViewById (dest);
        destim.setDrawingCacheEnabled(true);
        destim.setImageBitmap(bitmap);

我已经读到,您不能有超过2个分配。所以,我猜这是我的问题。因此,我想尝试以uchar4*的形式阅读中的颜色,但我找不到一个如何做到这一点的示例

代码看起来不错,你能描述一下哪里出了问题吗?只是输出的位图不是你所期望的吗?另外,我建议使用rsGetElementAt_uchar4(colors,col,0),这将更快,并在那里添加#pragma rs_fp_relaxedHi!!问题是这些值始终为0。但是,最后我把它分解成3个int数组,每个数组包含r,g,b,然后使用它们,这样就可以了。
Bitmap.Config conf = Bitmap.Config.ARGB_8888; // see other conf types
Bitmap myBitmap = Bitmap.createBitmap(pickedPanels.size(), 1, conf);
myBitmap.setPixels(myInts, 0, myBitmap.getWidth(), 0, 0, myBitmap.getWidth(),0);

final RenderScript rs = RenderScript.create(this);

// The input image.
final Allocation input = Allocation.createFromBitmap(rs, bitmap, Allocation.MipmapControl.MIPMAP_NONE,
Allocation.USAGE_SCRIPT);

// The output image.
final Allocation output = Allocation.createTyped(rs, input.getType());
        final ScriptC_singlesource script = new 

ScriptC_singlesource(rs);

// The array of colours.
final Allocation pixels = Allocation.createFromBitmap(rs, myBitmap, Allocation.MipmapControl.MIPMAP_NONE,
                Allocation.USAGE_SCRIPT);
script.set_image(pixels);
script.set_imgWidth(pickedPanels.size());
script.forEach_root(input, output);
// retrieve output
output.copyTo(bitmap);

        ImageView destim = (ImageView) findViewById (dest);
        destim.setDrawingCacheEnabled(true);
        destim.setImageBitmap(bitmap);