佳能EDSDK将图像保存在我的PC中 [英] canon EDSDK saving image in my PC
问题描述
我在EOS 50D相机上使用EDSDK v2.13.我想将拍摄的照片保存在主机中.我正在使用此代码(c ++):
I am using EDSDK v2.13 with my EOS 50D camera. I want to save taken pictures in my host. I am using this code (c++):
EdsOpenSession(camera);
EdsInt32 saveTarget = kEdsSaveTo_Both;
err = EdsSetPropertyData( camera, kEdsPropID_SaveTo, 0, 4, &saveTarget );
EdsCapacity newCapacity = {0x7FFFFFFF, 0x1000, 1};
err = EdsSetCapacity(camera, newCapacity);
const char* ch_dest = "C:\\photo\\Img.jpg";
EdsCreateFileStreamEx( ch_dest ,kEdsFileCreateDisposition_CreateNew,kEdsAccess_ReadWrite, 0);
EdsSendCommand(camera, kEdsCameraCommand_TakePicture, 0);
EdsCloseSession(camera);
EdsTerminateSDK();
相机快门正常闪光,我在相机的存储卡中找到了图片,但在PC上找不到它.
The camera shutter fires normally and I find the picture in the memory card of my camera but I cannot find it in my PC.
请帮助.
推荐答案
它不能那样工作.拍摄完照片后,您需要捕获ObjectEvent,然后下载文件.它的工作原理如下:
it doesn't work that way. After you have taken the photo you need to catch the ObjectEvent and then download the file. It works something like this:
- 公开会议
- 设置SaveTo_Both或主机
- 设置容量
- 使用EdsSetObjectEventHandler订阅对象事件
- 拍照
- 对象事件应以"inEvent"为"kEdsObjectEvent_DirItemRequestTransfer"触发
- 下载数据:
- 通过EdsGetDirectoryItemInfo获取信息,其中事件中"inDirItemRef"为"inRef"
- 使用EdsCreateFileStream创建文件流
- 使用EdsDownload下载数据(事件中的inRef,DirectoryItemInfo中的大小)
- 使用EdsDownloadComplete(事件中的inRef)标记为完成
- 使用EdsRelease(事件中的inRef)释放数据
- 使用EdsRelease释放流
很抱歉,我无法为您提供实际的代码,我不是C ++开发人员.如果您愿意,我可以向您展示一些C#代码.要获得有关这些功能如何工作的更多详细信息,您还可以查看SDK的文档.
I'm sorry that I can't provide you actual code, I'm not a C++ developer. If you want I can show you some C# code though. To get more details on how the functions work, you could also check the documentation of the SDK.
亲切的问候
好吧,在文档的帮助下,一些C ++代码:请注意,这就是它以barest形式工作的方式.您应该始终检查err!= EDS_ERR_OK.而且,只有在下载图像后,您才应该调用关闭".
Ok, some C++ code with help of the documentation: Note that this is how it would work in it's barest form. You should always check if err != EDS_ERR_OK. And you should call Close only after the image has been downloaded.
void TakePhoto() { EdsError err = EDS_ERR_OK; EdsCameraRef camera = NULL; EdsCameraListRef cameraList = NULL; EdsUInt32 count = 0; err = EdsInitializeSDK(); err = EdsGetCameraList(&cameraList); err = EdsGetChildCount(cameraList, &count); if (count > 0) { err = EdsGetChildAtIndex(cameraList, 0, &camera); cameraList = NULL; err = EdsSetObjectEventHandler(camera, kEdsObjectEvent_All, handleObjectEvent, NULL); err = EdsOpenSession(camera); err = EdsSendCommand(camera, kEdsCameraCommand_TakePicture, 0); } } void Close(EdsCameraRef *camera) { err = EdsCloseSession(camera); EdsRelease(camera); EdsTerminateSDK(); } static EdsError EDSCALLBACK handleObjectEvent(EdsObjectEvent event, EdsBaseRef object, EdsVoid * context) { if (event == kEdsObjectEvent_DirItemRequestTransfer) { EdsError err = EDS_ERR_OK; EdsStreamRef stream = NULL; EdsDirectoryItemInfo dirItemInfo; err = EdsGetDirectoryItemInfo(object, &dirItemInfo); err = EdsCreateFileStream(dirItemInfo.szFileName, kEdsFileCreateDisposition_CreateAlways, kEdsAccess_ReadWrite, &stream); err = EdsDownload(object, dirItemInfo.size, stream); err = EdsDownloadComplete(object); EdsRelease(stream); stream = NULL; } if (object) EdsRelease(object); }
这篇关于佳能EDSDK将图像保存在我的PC中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!