C# DllImport - 指向接收图像的指针 (uchar**)
C# DllImport - pointer to a pointer receiving image (uchar**)
我正在尝试 DLLImport 函数 simxGetVisionSensorImage
来自 v-rep 软件的 remoteApi.dll
。这是函数描述的link:
http://www.coppeliarobotics.com/helpFiles/en/remoteApiFunctions.htm#simxGetVisionSensorImage
下面是上面link:
对这个函数的简要描述
描述:检索视觉传感器的图像。如果之前未调用 simHandleVisionSensor,则返回的数据没有意义(如果视觉传感器未标记为显式处理,则在主脚本中默认调用 simHandleVisionSensor)。使用 simxGetLastCmdTime 函数验证检索到的数据的"freshness"。
C 概要: simxInt simxGetVisionSensorImage(simxInt clientID,simxInt sensorHandle,simxInt* resolution,simxUChar** image,simxUChar options,simxInt operationMode)
C参数:
clientID: 客户端 ID。参考simxStart.
sensorHandle:视觉传感器的句柄
分辨率: 指向接收图像分辨率的 2 个 simxInt 值的指针
image: pointer to 指向图像数据的指针。
options: image options, bit-coded: bit0 set: 每个图像像素是一个字节(灰度图像),否则每个图像像素是一个 rgb 字节三元组
operationMode:远程API功能操作模式。
这是我导入它的方式(simxGetVisionSensorImage
函数):
[DllImport("remoteApi.dll", CallingConvention = CallingConvention.Cdecl)]
public extern static simx_error simxGetVisionSensorImage(int clientID, int sensorHandle, out int resolution, out IntPtr image, char option, simx_opmode opmode);
我是这样称呼它的:
int intResolution = 0;
char option = '[=11=]';
IntPtr imageIntPtr= IntPtr.Zero;
simxGetVisionSensorImage(intClientID, intCamera1Handle, out intResolution, out imageIntPtr, option, simx_opmode.streaming);
运行成功,intResolution 为 128,imageIntPtr 在 运行 后也被验证。但是,我不知道如何将 "imageIntPtr" 变量转换为图像或位图。
如果有人能帮助我,我将不胜感激。
最简单的方法是从中构造一个新的 Bitmap
。
var bmp = new Bitmap(bitmapWidth, bitmapHeight, 3 * bitmapWidth,
PixelFormat.Format24bppRgb, ptrFromApi);
我正在尝试 DLLImport 函数 simxGetVisionSensorImage
来自 v-rep 软件的 remoteApi.dll
。这是函数描述的link:
http://www.coppeliarobotics.com/helpFiles/en/remoteApiFunctions.htm#simxGetVisionSensorImage
下面是上面link:
对这个函数的简要描述描述:检索视觉传感器的图像。如果之前未调用 simHandleVisionSensor,则返回的数据没有意义(如果视觉传感器未标记为显式处理,则在主脚本中默认调用 simHandleVisionSensor)。使用 simxGetLastCmdTime 函数验证检索到的数据的"freshness"。
C 概要: simxInt simxGetVisionSensorImage(simxInt clientID,simxInt sensorHandle,simxInt* resolution,simxUChar** image,simxUChar options,simxInt operationMode)
C参数:
clientID: 客户端 ID。参考simxStart.
sensorHandle:视觉传感器的句柄
分辨率: 指向接收图像分辨率的 2 个 simxInt 值的指针
image: pointer to 指向图像数据的指针。
options: image options, bit-coded: bit0 set: 每个图像像素是一个字节(灰度图像),否则每个图像像素是一个 rgb 字节三元组
operationMode:远程API功能操作模式。
这是我导入它的方式(simxGetVisionSensorImage
函数):
[DllImport("remoteApi.dll", CallingConvention = CallingConvention.Cdecl)]
public extern static simx_error simxGetVisionSensorImage(int clientID, int sensorHandle, out int resolution, out IntPtr image, char option, simx_opmode opmode);
我是这样称呼它的:
int intResolution = 0;
char option = '[=11=]';
IntPtr imageIntPtr= IntPtr.Zero;
simxGetVisionSensorImage(intClientID, intCamera1Handle, out intResolution, out imageIntPtr, option, simx_opmode.streaming);
运行成功,intResolution 为 128,imageIntPtr 在 运行 后也被验证。但是,我不知道如何将 "imageIntPtr" 变量转换为图像或位图。
如果有人能帮助我,我将不胜感激。
最简单的方法是从中构造一个新的 Bitmap
。
var bmp = new Bitmap(bitmapWidth, bitmapHeight, 3 * bitmapWidth,
PixelFormat.Format24bppRgb, ptrFromApi);