|
申し訳ありません。気を付けます
AForge.Video.DirectShowを使っています ソースです using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using DarrenLee.Media; using System.IO; using System.Drawing.Imaging;
namespace MainWebCamProject2 { public partial class TakePicture : Form { Camera myCamera = new Camera();
public TakePicture() { InitializeComponent();
GetInfo(); myCamera.OnFrameArrived += myCamera_OnFrameArrived; DateTime dt = DateTime.Now; textBox1.Text = dt.ToString(); }
private void myCamera_OnFrameArrived(object source, FrameArrivedEventArgs e) { Image img = e.GetFrame(); pictureBox1.Image = img; } private void GetInfo() { var cameraDevices = myCamera.GetCameraSources(); var cameraResolution = myCamera.GetSupportedResolutions();
foreach (var d in cameraDevices) { comboBox1.Items.Add(d); } foreach (var r in cameraResolution) { comboBox2.Items.Add(r); }
comboBox1.SelectedIndex = 0; comboBox2.SelectedIndex = 0; }
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { myCamera.ChangeCamera(comboBox1.SelectedIndex); }
private void comboBox2_SelectedIndexChanged(object sender, EventArgs e) { myCamera.Start(comboBox2.SelectedIndex); }
private void TakePicture_FormClosing(object sender, FormClosingEventArgs e) { myCamera.Stop(); }
private void btnSave_Click(object sender, EventArgs e) { try { if (Directory.Exists(@"C:\DB\images")) { //Directory.CreateDirectory(@"C:\DB\images"); //MessageBox.Show("Image Folder Created..."); //} //else //{ string path = @"C:\DB\images"; DateTime dt = DateTime.Now; pictureBox1.Image.Save(path + @"\" + dt.ToString("yyyyMMdd") + "_"+dt.ToString("HHmmss") + "-" + textBox1.Text + ".jpg",ImageFormat.Jpeg); } } catch (Exception ex) { MessageBox.Show(ex.Message); }
}
private void TakePicture_Load(object sender, EventArgs e) {
} } } 宜しくお願い致します
|