2

我想在ac#或VB.NET程序中使用canon EDSDK来查看cr2文件。

我找到了有关如何控制相机的示例代码 - 例如:

https://github.com/esskar/Canon.Eos.Framework

但没有关于打开文件、提取图像数据并显示它 - 或将拇指或全尺寸图像保存为 jpg...

有人可以指导我一些这样的例子吗?谢谢你。

注意 - 我有 EDSDK 2.12,我希望旧版本也能有所帮助。

编辑:感谢您的建议,它指向一个可能有帮助的 C 库......虽然我不知道如何,但不知道如何在 dot net 中使用它。

4

1 回答 1

3

I know it's been a while since this question has been asked, still it might help someone. To process canon raw files with the SDK you have to do this:

uint err;
//Create input stream
IntPtr inStream;
err = EDSDK.EdsCreateFileStream("Test.CR2", EDSDK.EdsFileCreateDisposition.OpenExisting, EDSDK.EdsAccess.Read, out inStream);
//Create image reference
IntPtr imgRef;
err = EDSDK.EdsCreateImageRef(inStream, out imgRef);

//Set properties
err = EDSDK.EdsSetPropertyData(imgRef, EDSDK.PropID_WhiteBalance, 0, 4, EDSDK.WhiteBalance_Cloudy);
//TODO: set any imageRef compatible property you need here.

//Create output stream
IntPtr outStream;
err = EDSDK.EdsCreateFileStream("TestOut.jpg", EDSDK.EdsFileCreateDisposition.CreateAlways, EDSDK.EdsAccess.Write, out outStream);
//Get image info
EDSDK.EdsImageInfo info;
err = EDSDK.EdsGetImageInfo(imgRef, EDSDK.EdsImageSource.FullView, out info);
//Set image settings
EDSDK.EdsSaveImageSetting set = new EDSDK.EdsSaveImageSetting();
set.JPEGQuality = 9;
//Save image
err = EDSDK.EdsSaveImage(imgRef, EDSDK.EdsTargetImageType.Jpeg, set, outStream);

//Release data
EDSDK.EdsRelease(imgRef);
EDSDK.EdsRelease(inStream);
EDSDK.EdsRelease(outStream);

Of course you don't have to read a file from the HD but can also use an image reference you got from the camera.

Another way to get preview images without the SDK would be to read out the CR2 itself. It is basically just a Tiff file and it stores a jpg thumbnail (160x120) and two a bit bigger RGB images. This website here provides some good information about the whole CR2 format: http://lclevy.free.fr/cr2/

Kind regards

于 2014-04-10T14:10:42.350 回答