我正在尝试使用 monotouch 绑定到第 3 方条码扫描库 - 到目前为止,除了库头文件中定义的以下方法外,一切都运行良好:
/**
* 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,映射为“扫描失败”。任何解决此问题的帮助将不胜感激。