我试图绑定到使用monotouch的第三方条码扫描库 - 除了以下方法之外,一切工作都很顺利库头文件:在Monotouch中绑定到第三方库 - 映射uint8_t *和uint8_t **
/**
* Main scan function. Invokes all activated decoders by priority.
* For successful scan, allocates pp_data buffer and pass it to user.
* User should deallocate *pp_data pointer when no more needed.
*
* @param[in] pp_image Byte array representing grayscale value of image pixels.
* Array shold be stored in row after row fashion, starting with top row.
* @param[in] lenX X axis size (width) of image.
* @param[in] lenY Y axis size (length) of image.
* @param[out] pp_data On successful decode, library allocates new byte array where it stores decoded
* string result. Pointer to string is passed here. User application is responsible
* for deallocating this buffer after use.
*
* @retval >0 Result string length for successful decode
* @retval MWB_RT_BAD_PARAM Null pointer or out of range parameters
* @retval MWB_RT_NOT_SUPPORTED Unsupported decoder found in execution list - library error
*/
extern int MWB_scanGrayscaleImage(uint8_t * pp_image, int lenX, int lenY, uint8_t **pp_data);
它已经一段时间,因为我与C数据结构直接处理,而我不是如何映射uint8_t * pp_image
和uint8_t **pp_data
清晰。
第一个参数处理来自像素缓冲区的灰度图像。我从CMSampleBuffer
获得图像缓冲区。它是否需要亮度转换的字节数组,字节数组的内存地址,还是会传入pixelBuffer.GetBaseAddress(0)
作为IntPtr
就足够了?
最后一个参数被传入一个指针,该指针在objective-C演示中被初始化为unsigned char *pResult=NULL;
,然后在找到有效扫描时被填充数据。再次,我不确定如何初始化并传入,因为您无法在C#中传入未初始化/空字节数组。
我绑定库的代码是目前如下(虽然我也用IntPtr
尝试,由参传递,并通过不安全的方式直接地址):
[DllImport ("__Internal")]
extern static int MWB_scanGrayscaleImage (byte[] pp_image, int lenX, int lenY, out byte[] pp_data);
public static int ScanGrayscaleImage (byte[] pp_image, int lenX, int lenY, out byte[] pp_data)
{
int result = MWB_scanGrayscaleImage(pp_image, lenX, lenY, out pp_data);
return result;
}
一切到目前为止,我已经试过了,结果值保持返回-1,映射到“扫描失败”。任何帮助搞清楚这将不胜感激。
完美运行 - 谢谢! – JohnSvo