如何使用 vb.net 或 asp.net 或 C# 从通过 USB 电缆连接到计算机的数码相机拍照?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/75691/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-03 11:12:46  来源:igfitidea点击:

how do i take picture from a digital camera attached to my computer throught USB cable using vb.net or asp.net or C#?

提问by bugBurger

I am writing picture editing windows forms application using vb.net/c#. i have a client requirement to capture the photo from digital still camera attached to computer.

我正在使用 vb.net/c# 编写图片编辑 Windows 窗体应用程序。我有一个客户要求从连接到计算机的数码相机拍摄照片。

how can i capture a photo from USB connected digital still camera device in my windows application ?

如何在我的 Windows 应用程序中从 USB 连接的数码相机设备捕获照片?

采纳答案by Ilya

If you use the Windows Image Acquisition Library, you'll see events there for capturing camera new picture events. I had a similar requirement and wrote a test rig; we went down to the local camera store and tried every camera they had. The only cameras we could find that supported this functionality were the Nikon D-series cameras.

如果您使用 Windows 图像采集库,您将在那里看到用于捕获相机新图片事件的事件。我有一个类似的要求并编写了一个测试设备;我们去了当地的相机店,尝试了他们所有的相机。我们能找到的唯一支持此功能的相机是尼康 D 系列相机。

We found that with most cameras, you can't even take a picture when they are plugged in. When you plug them in to the USB port, most cameras will switch into a mode where the only thing they'll do is transfer data. The quick way to find out if a camera will work at all is to plug it into a PC, then try to snap a picture. If it lets you do that you have a chance. It also needs to support PTP.

我们发现对于大多数相机,当它们插入时你甚至无法拍照。当你将它们插入 USB 端口时,大多数相机会切换到一种模式,它们唯一会做的就是传输数据。确定相机是否能正常工作的快速方法是将其插入 PC,然后尝试拍摄照片。如果它让你这样做,你就有机会。它还需要支持PTP。

回答by Alex Duggleby

Usually the camera is displayed as a removable drive when attached.

通常,相机在连接时显示为可移动驱动器。

So for a Winforms application just let the user select the drive and the picture you want to upload. You can do any processing once you have the FileStream of the picture.

因此,对于 Winforms 应用程序,只需让用户选择要上传的驱动器和图片。一旦您拥有图片的 FileStream,您就可以进行任何处理。

In ASP.net you are going to need a FileUpload Control where again the user can select the drive and picture to upload. Processing this time would be via MemoryStream on the HttpRequest.Files object.

在 ASP.net 中,您将需要一个 FileUpload Control,用户可以再次选择要上传的驱动器和图片。这次将通过 HttpRequest.Files 对象上的 MemoryStream 进行处理。

Hope that helps.

希望有帮助。

回答by Sean McMains

This depends on your camera.

这取决于您的相机。

Many cameras will simply mount as USB mass storage devices. If this is the case, then you can just copy the file from the visible file system like you would any other file on an external disk.

许多相机将简单地安装为 USB 大容量存储设备。如果是这种情况,那么您可以像复制外部磁盘上的任何其他文件一样,从可见文件系统复制文件。

If the camera doesn't make its contents available in this way, you'll need to look at the camera driver documentation to see how they recommend interacting with it.

如果相机没有以这种方式提供其内容,您需要查看相机驱动程序文档以了解他们建议如何与之交互。

回答by Mark Ransom

It will depend on the brand of camera. Here is a link to start with for Canon.

这将取决于相机的品牌。这是佳能的开始链接。

回答by Sam

I assume you want to activate the action of taking a picture from the computer which the camera is attached to. If that is the case then the first thing I would do is search for an API for that particular camera model. I don't believe there is a standard protocol/framework for interacting with digital cameras besides accessing the memory card within the camera.

我假设您要激活从连接相机的计算机拍摄照片的动作。如果是这种情况,那么我要做的第一件事就是搜索该特定相机型号的 API。我不相信除了访问相机内的存储卡之外,还有用于与数码相机交互的标准协议/框架。

回答by Ilya

This is depend on the interface the camera exporting. If this is standard mass storage interface you just use standard file interface, i.e you will see the camera as removable disk and can use standard Create/Read/Write/File operation.
Many new cameras have ptp (Picture transport protocol) interface. So you will need using Windows Image AcquisitionAPI.

这取决于相机导出的接口。如果这是标准的大容量存储接口,您只需使用标准的文件接口,即您将看到相机作为可移动磁盘,可以使用标准的创建/读取/写入/文件操作。
许多新相机都有 ptp(图片传输协议)接口。所以你需要使用Windows Image AcquisitionAPI。

You might find useful following Link. If i understand correctly this is a sample code for exactly what are you looking for. Google is your friend :)

您可能会发现以下链接很有用。如果我理解正确,这是您正在寻找的示例代码。谷歌是你的朋友 :)

Another piece of info: many cameras will support both mass storage and ptp interfaces and it will be selectable by camera user interface. In case of automatic mode camera probably will switch to ptp interface.

另一条信息:许多相机将同时支持大容量存储和 ptp 接口,并且可以通过相机用户界面进行选择。在自动模式相机的情况下可能会切换到 ptp 界面。