Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/258.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
C#DllImport-指向指针接收图像的指针(uchar**)_C#_Image_Dllimport - Fatal编程技术网

C#DllImport-指向指针接收图像的指针(uchar**)

C#DllImport-指向指针接收图像的指针(uchar**),c#,image,dllimport,C#,Image,Dllimport,我正在尝试DLLImport函数simxGetVisionSensorImage 从v-rep软件的remoteApi.dll。以下是指向功能说明的链接: 以下是上述链接对该功能的简要说明: 说明:检索视觉传感器的图像。如果之前未调用simHandleVisionSensor,则返回的数据没有意义(如果vision sensor未标记为显式处理,则默认情况下在主脚本中调用simHandleVisionSensor)。使用simxGetLastCmdTime函数验证检索到的数据的“新鲜度” C简

我正在尝试DLLImport函数
simxGetVisionSensorImage
从v-rep软件的
remoteApi.dll
。以下是指向功能说明的链接:

以下是上述链接对该功能的简要说明:

说明:检索视觉传感器的图像。如果之前未调用simHandleVisionSensor,则返回的数据没有意义(如果vision sensor未标记为显式处理,则默认情况下在主脚本中调用simHandleVisionSensor)。使用simxGetLastCmdTime函数验证检索到的数据的“新鲜度”

C简介:simxInt-simxGetVisionSensorImage(simxInt-clientID、simxInt-sensorHandle、simxInt*分辨率、simxUChar**图像、simxUChar选项、simxInt操作模式)

C参数:
客户端ID:客户端ID。请参阅simxStart

传感器手柄:视觉传感器手柄

分辨率:指向接收图像分辨率的2个simxInt值的指针

图像:指向图像数据指针的指针

选项:图像选项,位编码:位0设置:每个图像像素是一个字节(灰度图像),否则每个图像像素是一个rgb字节三元组

操作模式:远程API函数操作模式

以下是我导入它的方式(
simxGetVisionSensorImage
函数):

我这样称呼它:

int intResolution = 0;
char option = '\0';
IntPtr imageIntPtr= IntPtr.Zero;
simxGetVisionSensorImage(intClientID, intCamera1Handle, out intResolution, out imageIntPtr, option, simx_opmode.streaming);
它运行成功,intResolution为128,运行后还验证了imageIntPtr。但是,我不知道如何将“imageIntPtr”变量转换为图像或位图


如果有人能在这方面帮助我,我真的很感激。

最简单的方法就是从中构造一个新的


很有效,谢谢。但是,它会将红色更改为蓝色。你知道为什么吗?有些图像是RGB,有些是BGR。IIRC,System.Drawing.Bitmap需要BGR。无论哪种方式,每3个字节都需要将字节[0]与字节[2]交换一次。或者更好的方法是,如果可能的话,在API调用中更改像素格式。此页面有一个转换的代码示例:
int intResolution = 0;
char option = '\0';
IntPtr imageIntPtr= IntPtr.Zero;
simxGetVisionSensorImage(intClientID, intCamera1Handle, out intResolution, out imageIntPtr, option, simx_opmode.streaming);
var bmp = new Bitmap(bitmapWidth, bitmapHeight, 3 * bitmapWidth,
    PixelFormat.Format24bppRgb, ptrFromApi);