0

在我的 Android 代码中,我保留了一组我想在我的渲染脚本代码中使用的颜色,如下所示:

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;

所以基本上,如果像素是阵列中的一种颜色,则将其变为红色。问题是我正在努力分配像素数组。在 RS 我有:

 rs_allocation colours;
 int imgWidth;

在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* 的形式读取颜色,但我找不到如何执行此操作的示例。

4

0 回答 0