我正在尝试将我的佳能相机拍摄的图像从SD卡下载到主机PC,我已编写代码以便拍摄,不再将其保存在SD卡上,但我找不到它也在主机PC上。有没有人有任何指示?我的主要功能和功能如下所示,不包括getFirstCamera功能。
我真的不知道回调函数等是如何工作的......所以如果有任何事情需要修复,那么任何人都能提供代码片段会很棒
#include <stdio.h>
#include "EDSDK.h"
#include "EDSDKTypes.h"
#include "EDSDKErrors.h"
EdsError getFirstCamera(EdsCameraRef *camera);
EdsError downloadImage(EdsDirectoryItemRef directoryItem);
EdsError EDSCALLBACK handleStateEvent (EdsStateEvent event,EdsUInt32 parameter,EdsVoid * context);
EdsError EDSCALLBACK handleObjectEvent( EdsObjectEvent event,EdsBaseRef object,EdsVoid * context);
EdsError EDSCALLBACK handlePropertyEvent (EdsPropertyEvent event,EdsPropertyID property,EdsUInt32 inParam, EdsVoid * context);
int main(int argc, char **argv)
{
EdsError err;
EdsCameraRef camera = NULL;
bool isSDKLoaded = false;
EdsCapacity capacity = {0x7FFFFFFF, 0x1000, 1};
EdsInt32 saveTarget = kEdsSaveTo_Host;
// Initialize SDK
err = EdsInitializeSDK();
if(err == EDS_ERR_OK)
{
isSDKLoaded = true;
}
// Get first camera
if(err == EDS_ERR_OK)
{
err = getFirstCamera (&camera);
}
// Open session with camera
err = EdsOpenSession(camera);
// Set event handler
if(err == EDS_ERR_OK) err = EdsSetObjectEventHandler(camera, kEdsObjectEvent_All,handleObjectEvent, NULL);
if(err == EDS_ERR_OK) err = EdsSetPropertyEventHandler(camera, kEdsPropertyEvent_All,handlePropertyEvent, NULL);
if(err == EDS_ERR_OK) err = EdsSetCameraStateEventHandler(camera, kEdsStateEvent_All,handleStateEvent, NULL);
err = EdsSetPropertyData( camera, kEdsPropID_SaveTo, 0, 4, &saveTarget );
err = EdsSetCapacity(camera, capacity);
///// Take picture
err = EdsSendCommand(camera, kEdsCameraCommand_TakePicture, 0);
////
// Close session with camera
if(err == EDS_ERR_OK)
{
err = EdsCloseSession(camera);
}
// Release camera
if(camera != NULL)
{
EdsRelease(camera);
}
// Terminate SDK
if(isSDKLoaded)
{
EdsTerminateSDK();
}
}
EdsError EDSCALLBACK handleObjectEvent( EdsObjectEvent event,EdsBaseRef object,EdsVoid * context)
{
EdsError err=EDS_ERR_OK;
switch(event)
{
case kEdsObjectEvent_DirItemRequestTransfer:
err = downloadImage(object);
break;
default:
break;
}
// Object must be released
if(object){
err = EdsRelease(object);
}
return err;
}
EdsError EDSCALLBACK handlePropertyEvent (EdsPropertyEvent event,EdsPropertyID property,EdsUInt32 inParam, EdsVoid * context)
{
return EDS_ERR_OK;
}
EdsError EDSCALLBACK handleStateEvent (EdsStateEvent event,EdsUInt32 parameter,EdsVoid * context)
{
return EDS_ERR_OK;
}
EdsError downloadImage(EdsDirectoryItemRef directoryItem)
{
EdsError err = EDS_ERR_OK;
EdsStreamRef stream = NULL;
// Get directory item information
EdsDirectoryItemInfo dirItemInfo;
err = EdsGetDirectoryItemInfo(directoryItem, & dirItemInfo);
// Create file stream for transfer destination
if(err == EDS_ERR_OK)
{
err = EdsCreateFileStream( dirItemInfo.szFileName,kEdsFileCreateDisposition_CreateAlways,kEdsAccess_ReadWrite, &stream);
}
// Download image
if(err == EDS_ERR_OK)
{
err = EdsDownload( directoryItem, dirItemInfo.size, stream);
}
// Issue notification that download is complete
if(err == EDS_ERR_OK)
{
err = EdsDownloadComplete(directoryItem);
}
// Release stream
if( stream != NULL)
{
EdsRelease(stream);
stream = NULL;
}
return err;
}
答案 0 :(得分:1)
当您调用EdsCreateFileStream时,只需在您希望文件到达的位置添加完全限定的路径。 dirItemInfo.szFileName只是文件名,因此如果您不包含路径,图像应该出现在您的工作目录中。