问题描述
我是编程的新手,但尝试在 VS2019 中运行我的第一个应用程序,C# .NET。我想从我的 USB 显微镜中取出一个 Snapshop。我找到了 OZEKI SDK 库,并且能够连接和查看显微镜中的图像。 Ozeki 在 youtube 上有一个教程:
https://www.youtube.com/watch?v=xjMAfMAix9c
和他们的网站,
https://www.camera-sdk.com/p_6553-how-to-take-a-picture-snapshot-and-save-it-as-.jpg-in-c-.html
但是当我尝试运行应用程序时,我收到消息: “images.save(curentpath)”对象不包含“save”的定义,也不能访问......”
代码:
using System;
using System.Drawing;
using System.Windows.Forms;
using Ozeki.Media;
using Ozeki.Camera;
namespace WindowsFormsApp3
{
public partial class Form1 : Form
{
private DrawingImageProvider _imageProvider;
private MediaConnector _connector;
private VideoViewerWF _videoViewerWf;
private SnapshotHandler _snapshotHandler;
private IWebCamera _webCamera;
public Form1()
{
InitializeComponent();
_imageProvider = new DrawingImageProvider();
_connector = new MediaConnector();
_snapshotHandler = new SnapshotHandler();
_videoViewerWf = new VideoViewerWF();
SetVideoViewer();
}
private void SetVideoViewer()
{
CameraBox.Controls.Add(_videoViewerWf);
_videoViewerWf.Size = new Size(260,180);
_videoViewerWf.BackColor = Color.Black;
_videoViewerWf.TabStop = false;
_videoViewerWf.Location = new Point(14,19);
_videoViewerWf.Name = "_videoViewerWf";
}
private void button_Connect_Click(object sender,EventArgs e)
{
_webCamera = new WebCamera();
if (_webCamera != null)
{
_connector.Connect(_webCamera.VideoChannel,_imageProvider);
_connector.Connect(_webCamera.VideoChannel,_snapshotHandler);
_videoViewerWf.SetimageProvider(_imageProvider);
_webCamera.Start();
_videoViewerWf.Start();
}
}
private void button_Saveto_Click(object sender,EventArgs e)
{
var result = folderbrowserDialog1.ShowDialog();
if (result == DialogResult.OK)
TextBox_Saveto.Text = folderbrowserDialog1.Selectedpath;
}
private void Btn_Snapshot_Click(object sender,EventArgs e)
{
var path = TextBox_Saveto.Text;
CreateSnapShot(path);
}
private void CreateSnapShot(string path)
{
var date = DateTime.Now.Year + "y-" + DateTime.Now.Month + "m-" + DateTime.Now.Day + "d-" +
DateTime.Now.Hour + "h-" + DateTime.Now.Minute + "m-" + DateTime.Now.Second + "s";
string currentpath;
if (String.IsNullOrEmpty(path))
currentpath = date + ".jpg";
else
currentpath = path + "\\" + date + ".jpg";
var snapShotimage = _snapshotHandler.TakeSnapshot().ToImage();
snapShotimage.Save(currentpath,System.Drawing.Imaging.ImageFormat.Jpeg);
}
}
}
和设计师:
namespace WindowsFormsApp3
{
partial class Form1
{
private System.ComponentModel.IContainer components = null;
protected override void dispose(bool disposing)
{
if (disposing && (components != null))
{
components.dispose();
}
base.dispose(disposing);
}
private void InitializeComponent()
{
this.folderbrowserDialog1 = new System.Windows.Forms.FolderbrowserDialog();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.button_Connect = new System.Windows.Forms.Button();
this.CameraBox = new System.Windows.Forms.GroupBox();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.TextBox_Saveto = new System.Windows.Forms.TextBox();
this.Btn_Snapshot = new System.Windows.Forms.Button();
this.button_Saveto1 = new System.Windows.Forms.Button();
this.groupBox1.SuspendLayout();
this.groupBox2.SuspendLayout();
this.SuspendLayout();
//
// groupBox1
//
this.groupBox1.Controls.Add(this.button_Connect);
this.groupBox1.Location = new System.Drawing.Point(10,10);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(120,60);
this.groupBox1.TabIndex = 0;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Connect";
//
// button_Connect
//
this.button_Connect.Font = new System.Drawing.Font("Microsoft Sans Serif",8.5F,System.Drawing.FontStyle.Regular,system.drawing.graphicsUnit.Point,((byte)(238)));
this.button_Connect.ForeColor = System.Drawing.Color.Black;
this.button_Connect.Location = new System.Drawing.Point(10,20);
this.button_Connect.Name = "button_Connect";
this.button_Connect.Size = new System.Drawing.Size(100,25);
this.button_Connect.TabIndex = 6;
this.button_Connect.Text = "Connect";
this.button_Connect.UseVisualStyleBackColor = true;
this.button_Connect.Click += new System.EventHandler(this.button_Connect_Click);
//
// CameraBox
//
this.CameraBox.Location = new System.Drawing.Point(10,80);
this.CameraBox.Name = "CameraBox";
this.CameraBox.Size = new System.Drawing.Size(285,210);
this.CameraBox.TabIndex = 3;
this.CameraBox.TabStop = false;
this.CameraBox.Text = "Live camera ";
//
// groupBox2
//
this.groupBox2.Controls.Add(this.TextBox_Saveto);
this.groupBox2.Controls.Add(this.Btn_Snapshot);
this.groupBox2.Controls.Add(this.button_Saveto1);
this.groupBox2.Location = new System.Drawing.Point(10,300);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(285,100);
this.groupBox2.TabIndex = 37;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "Snapshot";
//
// TextBox_Saveto
//
this.TextBox_Saveto.Location = new System.Drawing.Point(119,63);
this.TextBox_Saveto.Name = "TextBox_Saveto";
this.TextBox_Saveto.Size = new System.Drawing.Size(160,20);
this.TextBox_Saveto.TabIndex = 35;
this.TextBox_Saveto.Text = "C:\\Users\\user\\Documents\\Visual Studio 2012\\Projects\\03_Onvif_Network_Video_Record" +
"er\\03_Onvif_Network_Video_Recorder\\bin\\Debug";
//
// Btn_Snapshot
//
this.Btn_Snapshot.Location = new System.Drawing.Point(10,20);
this.Btn_Snapshot.Name = "Btn_Snapshot";
this.Btn_Snapshot.Size = new System.Drawing.Size(100,25);
this.Btn_Snapshot.TabIndex = 36;
this.Btn_Snapshot.Text = "Take a snapshot";
this.Btn_Snapshot.UseVisualStyleBackColor = true;
this.Btn_Snapshot.Click += new System.EventHandler(this.Btn_Snapshot_Click);
//
// button_Saveto1
//
this.button_Saveto1.Location = new System.Drawing.Point(10,60);
this.button_Saveto1.Name = "button_Saveto1";
this.button_Saveto1.Size = new System.Drawing.Size(100,25);
this.button_Saveto1.TabIndex = 34;
this.button_Saveto1.Text = "Save to:";
this.button_Saveto1.UseVisualStyleBackColor = true;
this.button_Saveto1.Click += new System.EventHandler(this.button_Saveto_Click);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.Sizef(6F,13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(309,414);
this.Controls.Add(this.groupBox2);
this.Controls.Add(this.CameraBox);
this.Controls.Add(this.groupBox1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
this.Name = "Form1";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Network Video Recorder Snapshot";
this.groupBox1.ResumeLayout(false);
this.groupBox2.ResumeLayout(false);
this.groupBox2.Performlayout();
this.ResumeLayout(false);
}
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.Button button_Connect;
private System.Windows.Forms.GroupBox CameraBox;
private System.Windows.Forms.TextBox TextBox_Saveto;
private System.Windows.Forms.Button button_Saveto1;
private System.Windows.Forms.FolderbrowserDialog folderbrowserDialog1;
private System.Windows.Forms.Button Btn_Snapshot;
private System.Windows.Forms.GroupBox groupBox2;
}
}
在此先感谢您的帮助。
解决方法
好的,我做到了。更改:
var snapShotImage = _snapshotHandler.TakeSnapshot().ToImage();
到
var snapShotImage = _snapShot.TakeSnapshot().ToImage() as System.Drawing.Image;