Canon SDK example for image processing

徘徊边缘 提交于 2021-02-08 03:49:37

问题


I would like to use the canon EDSDK in a c# or VB.NET program, to view cr2 files.

I have found sample code on how to control the camera - example:

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

but nothing about opening the files, extracting the image data and displaying it - or saving the thumbs or full sized image as a jpg...

Could someone direct me to some such examples ? Thank you.

Note - I have EDSDK 2.12, i hope older versions could also help.

Edit: Thank you for the suggestion, it points to a C library that may help... Though I don't know how, not sure how i can use it in dot net.


回答1:


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



来源:https://stackoverflow.com/questions/17053354/canon-sdk-example-for-image-processing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!