我需要为佳能相机中的实时视图图像创建一个函数,但当我尝试使用佳能提供的示例代码时,我在变量中遇到了一些错误。所以我修改了代码,让它可以工作。但是函数EDSDK.EdsGetPropertyData返回代表错误EDS_ERR_INVALID_POINTER的错误代码98 (十六进制62)。我想知道我的代码中有什么错误,以及我如何处理它。
IntPtr outData;
public void startLiveview(IntPtr camera)
{
uint err = EDSDK.EDS_ERR_OK;
EDSDK.EdsDataType device = new EDSDK.EdsDataType();
int size;
EDSDK.EdsOpenSession(camera);
// Get the output device for the live view image EdsUInt32 device; err = EdsGetPropertyData(camera, kEdsPropID_Evf_OutputDevice, 0 , , sizeof(device), &device );
// PC live view starts by setting the PC as the output device for the live view image. if(err == EDS_ERR_OK) { device |= kEdsEvfOutputDevice_PC;
err = EDSDK.EdsGetPropertySize(camera, EDSDK.PropID_Evf_OutputDevice, 0,out device, out size);
MessageBox.Show("Error result:"+err.ToString());
MessageBox.Show(device.ToString());
MessageBox.Show(size.ToString());
err = EDSDK.EdsGetPropertyData(camera, EDSDK.PropID_Evf_OutputDevice, 0, size, outData);
MessageBox.Show(outData.ToString());
if (err == EDSDK.EDS_ERR_OK)
{
//type2.GetType();
//device |= EDSDK.PropID_Evf_OutputDevice;
// err = EDSDK.EdsSetPropertyData(camera, EDSDK.PropID_Evf_OutputDevice, 0, sizeof(device), &device);
}
else
{
MessageBox.Show("Error result:" + err.ToString());
}
EDSDK.EdsCloseSession(camera);
}发布于 2020-03-29 02:09:50
EdsGetPropertyData期望outData指针有一个值,但您传递的是零指针。
您需要先分配内存,然后调用EdsGetPropertyData,例如:
outData = System.Runtime.InteropServices.Marshal.AllocHGlobal(size);
err = EDSDK.EdsGetPropertyData(camera, EDSDK.PropID_Evf_OutputDevice, 0, size, outData);完成后,您必须释放已分配的内存,否则会发生内存泄漏:
System.Runtime.InteropServices.Marshal.FreeHGlobal(outData);在Canon SDK的C#示例中(我相信是从13.x版本开始),您应该发现已经为几种数据类型实现了EdsGetPropertyData方法的方法。为什么不使用这些而不是自己写呢?
https://stackoverflow.com/questions/60904015
复制相似问题