我的目标是使用佳能 EDSDK 3.4 将佳能 EOS 70D 拍摄的 RAW 图像保存为 .tif 文件,用于 WPF 应用程序。有人提到,此版本支持 RAW 图像处理。
从我的搜索中,我发现无法从相机中获取图像对象,因此您必须首先将图像下载到主机 PC,然后尝试读取文件以进行进一步处理并使用方法 EdsSaveImage( )。这是我拥有的代码。
private uint HandleObjectEvent(uint CamEvent, IntPtr direcItem, IntPtr context)
{
uint err = EDSDK.EDS_ERR_OK;
string path;
if (_cameraCaptureFileName != null)
{
path = ConfigFile.ConfigParams[CAMERA_CAPTURE_PATH] + _getBaseDirName(_cameraCaptureFileName);
}
else
path = ConfigFile.ConfigParams[CAMERA_CAPTURE_PATH];
string timeStamp = DateTime.Now.ToString();
ThreadPool.QueueUserWorkItem((state) =>
{
if (CamEvent == EDSDK.ObjectEvent_DirItemRequestTransfer)
{
IntPtr stream = IntPtr.Zero;
EDSDK.EdsDirectoryItemInfo dirItemInfo;
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
err = EDSDK.EdsGetDirectoryItemInfo(direcItem, out dirItemInfo);
if (_cameraCaptureFileName != null)
{
if (_isFileType(_cameraCaptureFileName, _imageType))
{
dirItemInfo.szFileName = path + "\\" + _getFileName(_cameraCaptureFileName);
}
else
System.Windows.MessageBox.Show("Filename is not an Image type","File type",
System.Windows.MessageBoxButton.OK,System.Windows.MessageBoxImage.Warning);
}
else
{
dirItemInfo.szFileName = path + "\\" + dirItemInfo.szFileName;
}
err = EDSDK.EdsCreateFileStream(dirItemInfo.szFileName, EDSDK.EdsFileCreateDisposition.CreateAlways,
EDSDK.EdsAccess.ReadWrite, out stream);
err = EDSDK.EdsDownload(direcItem, dirItemInfo.Size, stream);
err = EDSDK.EdsDownloadComplete(direcItem);
EDSDK.EdsRelease(stream);
stream = IntPtr.Zero;
IntPtr instream = IntPtr.Zero;
IntPtr imgref = IntPtr.Zero;
err = EdsCreateFileStream(dirItemInfo.szFileName, EdsFileCreateDisposition.OpenExisting, EdsAccess.Read, out instream);
err = EdsCreateImageRef(instream, out imgref);
}
});
return err;
}
因此,在代码的最后一部分中,我在 PC 上保存了 .CR2 格式的图像,并尝试使用EdsCreateFileStream(dirItemInfo.szFileName, EdsFileCreateDisposition.OpenExisting, EdsAccess.Read, out instream);
然后当我尝试使用err = EdsCreateImageRef(instream, out imgref);
创建图像对象时,错误代码显示 EDS_ERR_FILE_FORMAT_UNRECOGNIZED。我不明白为什么。我只能将 RAW 图像保存为 .tif 或 JPEG 格式,如果其中imgref
有一些价值的话。我尝试读取 JPEG 文件并成功。但是阅读 JPEG 对我来说毫无用处。请让我知道是否有任何设置需要更改。
以下链接中的方法是我想要做的。但它失败了。 佳能 SDk 文章,作者 Johannes Bildstein