我正在尝试编写一个程序来使用佳能 EOS700D 拍照并更改图像名称,并将该图像保存到某个目录。但我不知道为什么它不起作用!错误是 EDS_ERR_TAKE_PICTURE_CARD_NG。这是我的对象事件处理函数:
EdsError EDSCALLBACK SDKObjectEventHandler( EdsObjectEvent event, EdsImageRef object,
EdsVoid * context)
{
switch(event)
{
case kEdsObjectEvent_All:
break;
case kEdsObjectEvent_DirItemCancelTransferDT:
break;
case kEdsObjectEvent_DirItemContentChanged:
break;
case kEdsObjectEvent_DirItemCreated:
break;
case kEdsObjectEvent_DirItemInfoChanged:
break;
case kEdsObjectEvent_DirItemRemoved:
break;
case kEdsObjectEvent_DirItemRequestTransfer:
DownloadImage(object, ImageSaveDirectory);
break;
case kEdsObjectEvent_DirItemRequestTransferDT:
break;
case kEdsObjectEvent_FolderUpdateItems:
break;
case kEdsObjectEvent_VolumeAdded:
break;
case kEdsObjectEvent_VolumeInfoChanged:
break;
case kEdsObjectEvent_VolumeRemoved:
break;
case kEdsObjectEvent_VolumeUpdateItems:
break;
}
// Object must be released
if(object)
{
EdsRelease(object);
}
return EDS_ERR_OK;
}
和我的公开会议:
EdsError OpenSession(EdsCameraRef NewCamera)
{
//CamRef = NewCamera;
if (CameraSessionOpen) EdsCloseSession(NewCamera);
if (NewCamera != NULL)
{
//open a session
Error = EdsOpenSession(NewCamera);
//subscribe to the camera events (this time, in-Camera)
Error = EdsSetObjectEventHandler(NewCamera, kEdsObjectEvent_All, SDKObjectEventHandler, NULL);
Error = EdsSetPropertyEventHandler(NewCamera, kEdsPropertyEvent_All, SDKPropertyEventHandler, NULL);
Error = EdsSetCameraStateEventHandler(NewCamera,kEdsStateEvent_All, SDKStateEventHandler,NULL);
CameraSessionOpen = true;
}
return Error;
}
和下载图片:
EdsError DownloadImage(EdsDirectoryItemRef DirItemRef,string Sdirectory )
{
EdsDirectoryItemInfo dirInfo;
EdsStreamRef StreamRef;
//get information about object
Error = EdsGetDirectoryItemInfo(DirItemRef, &dirInfo);
if (Error != EDS_ERR_OK)
cout<< "SDK Error: " << Error << endl;
System::String^ CurrentPhoto2;
string extention = ".CR2" ;
System::String^ extention2 = gcnew System::String(extention.c_str());
System::Console::WriteLine(extention2);
System::String^ directory2 = gcnew System::String(Sdirectory.c_str());
System::Console::WriteLine(directory2);
if (ImageName!= 0 )
{
System::String^ ImageName2 = gcnew System::String(ImageName/*.c_str()*/);
System::Console::WriteLine(ImageName2);
CurrentPhoto2 = Path::Combine(directory2 , ImageName2 , extention2);
}
else
{
System::String^ FileName2 = gcnew System::String(dirInfo.szFileName);
System::Console::WriteLine(FileName2);
CurrentPhoto2 = Path::Combine(directory2,FileName2);
}
EdsChar* CurrentPhoto = (char*)System::Runtime::InteropServices::Marshal::StringToHGlobalAnsi(CurrentPhoto2).ToPointer();
System::Runtime::InteropServices::Marshal::FreeHGlobal((System::IntPtr) CurrentPhoto);
//create filestream to data
Error = EdsCreateFileStream(CurrentPhoto, kEdsFileCreateDisposition_CreateAlways, kEdsAccess_ReadWrite, &StreamRef);
//download file
Error = DownloadData(DirItemRef, StreamRef);
//release stream
Error = EdsRelease(StreamRef);
return Error;
}
最后是拍照功能:
EdsError TakePhoto(EdsCameraRef NewCamera)
{
int BusyCount = 0;
EdsError mErr = EDS_ERR_OK;
//sometimes the camera is not ready immediately
while (BusyCount < 20)
{
//send command to camera
ImageName = "red" ;
mErr = EdsSendCommand(NewCamera, kEdsCameraCommand_TakePicture, 0);
//if camera is busy, wait and try again
if (mErr == EDS_ERR_DEVICE_BUSY)
{
BusyCount++;
}
if (mErr != EDS_ERR_OK)
cout<< "SDK Error: " << mErr << endl;
}
Error = mErr;
return Error;
}
每件事似乎都是正确的!但它不起作用!:(请帮我...