佳能SDK-将图像下载到主机 [英] Canon SDK - Downloading image to host PC

查看:62
本文介绍了佳能SDK-将图像下载到主机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将佳能相机拍摄的图像从SD卡下载到主机PC,我编写了代码以使其能够拍摄并不再保存在SD卡上,但是我找不到它要么在主机上.有人有指示吗?我的主要和函数如下所示,但不包括getFirstCamera函数.

I'm trying to download the images taken by my canon camera from its SD card to the host PC, I've written code so that it takes a shot and no longer saves it on the SD card, but I cannot find it on the host PC either. Does anyone have any directions?? My main and functions is shown below, with the getFirstCamera function excluded.

我真的不知道回调函数等是如何工作的..因此,如果有人需要修复的话,如果有人可以提供代码片段,那将是很好的选择

I don't really know how the callback functions etc work at all.. so it'd be great if anyone could provide snippets of code if there're things to fix

#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;
}

推荐答案

调用EdsCreateFileStream时,只需在要将文件放入的标准路径前面添加.dirItemInfo.szFileName仅是文件名,因此,如果不包含路径,图像应显示在您的工作目录中.

When you call EdsCreateFileStream, just prepend the fully qualified path where you want the file to go. dirItemInfo.szFileName is the file name only, so the image should appear in your working directory if you don't include a path.

这篇关于佳能SDK-将图像下载到主机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆