在C语言中,我可以这样定义一个指向数组的指针:
我希望这样做,使用
char b1[SOME_SIZE];
char (*b3)[3]=(char(*)[3])b1;
因此,b3 [i] [j] == b1 [i * 3 + j]
。
我能在unsafe
C#中声明这样的指针b3
吗?
我的意图是访问位图通道,如下所示:
///...
unsafe {
//...
byte *target; //8bpp
byte (*source)[3]; //24bpp
//...
target[x]=(source[x][0]+source[x][1]+source[x][2])/3;
//...
我希望这样做,使用
source[x][ch]
代替source[x*3+ch]
来获得一些编译器优化。
byte*[]
,但这可能不是你想要的 - 请查看文档。 - BartoszKPSystem.Runtime.InteropServices
中的Marshal
类来避免访问非托管代码/指针。 - Erik