English 中文(简体)
Snapping pictures from Windows C# Canon SDK vs PTP or MTP
原标题:

I am hoping to receive some general guidance on accomplishing a seemingly simple goal. I have a DSLR camera (Canon EOS 50D) and need to write an application that will tell the camera to take a picture. I also need to transfer the picture to the computer and possibly delete it from the camera s storage. A bonus would be to get a live preview from the camera in my application. My environment will be Windows (either XP Pro or Vista Enterprise) and .Net 3.5 (C#).

I have done some research and found a couple of options. One I know will work, but limits me to using only Canon cameras in the future. I have found and downloaded an SDK from Canon that provides a lot of this functionality. I ve looked over the SDK and while it s extensive and written in C it does have C# wrappers that will speed up development a bit.

Another option I ve found is called Windows Portable Devices. Apparently, it is an API that will talk to devices that implement PTP and MTP standards. It is COM based and as far as I can tell it has no .Net wrappers. This is not however a show stopper. I could P/Invoke the functionality I need or write a Managed C++ DLL to use in my application to talk to the camera.

I am looking for anyone with experience with WPD to give me pointers. I ve perused the documentation and seen references to transferring images and deleting images. I have not, however, seen mention of commands to take a picture, get a preview image, or say focus/auto-focus.

最佳回答

The WPD api provides the command WPD_COMMAND_STILL_IMAGE_CAPTURE_INITIATE

I am not sure whether your camera supports it but it should be simple enough to find out. If you can get the "wpdinfo" tool from the driver development kit and start it with your camera connected then send it a WPD_COMMAND_CAPABILITIES_GET_SUPPORTED_COMMANDS command and see if it supports the still image capture command. IF so then you could give that a try.

问题回答

The comment from TallGanglyGuy is incorrect. ptp does allow you to trigger new images and change exposure, etc. Some cameras have firmware that only exposes some of the ptp commands.

PTP supports common device controls, such as taking a picture, so that the user could take advantage of the PC/camera combination in new and different ways again, without requiring additional software.

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

IMHO it s a better alternative then the .cs file that comes with the SDK.

PTP and MTP are both protocols for transferring files from a digital still camera (DSC). The protocols provide no functionality for triggering new images, or setting exposure control. You will be stuck using the camera specific SDK. If you want multiple vendor support Nikon has an SDK that provides similar support as the Canon SDK for their cameras.

More info on PTP and MTP can be found here: http://en.wikipedia.org/wiki/Picture_Transfer_Protocol and http://en.wikipedia.org/wiki/Media_Transfer_Protocol

EDIT

I forgot to mention that WIA may be interesting to you, assuming your camera s driver provides a WIA interface.

This is really generic, but it may help.

I had to write an application that used two different bar code scanners from two different vendors with different SDK s. I created an interface that defined the methods and events that I wanted to code for, and then wrote adapter classes that implemented my interface.

This worked well in my case, and switching from one to the other was pretty seamless. If you took the same approach, you wouldn t be totally dependent upon one SDK.





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签