73 lines
2.0 KiB
C#
73 lines
2.0 KiB
C#
|
|
using System;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using System.ComponentModel;
|
|||
|
|
using System.Data;
|
|||
|
|
using System.Drawing;
|
|||
|
|
using System.Drawing.Imaging;
|
|||
|
|
using System.Linq;
|
|||
|
|
using System.Runtime.InteropServices;
|
|||
|
|
using System.Text;
|
|||
|
|
using System.Windows.Forms;
|
|||
|
|
|
|||
|
|
namespace SOH.QianTai
|
|||
|
|
{
|
|||
|
|
public partial class FrmPaiZhao : Form
|
|||
|
|
{
|
|||
|
|
private Capture cam;
|
|||
|
|
|
|||
|
|
public FrmPaiZhao()
|
|||
|
|
{
|
|||
|
|
const int VIDEODEVICE = 0; // zero based index of video capture device to use
|
|||
|
|
const int VIDEOWIDTH = 640; // Depends on video device caps
|
|||
|
|
const int VIDEOHEIGHT = 480; // Depends on video device caps
|
|||
|
|
const int VIDEOBITSPERPIXEL = 24; // BitsPerPixel values determined by device
|
|||
|
|
|
|||
|
|
|
|||
|
|
InitializeComponent();
|
|||
|
|
cam = new Capture(VIDEODEVICE, VIDEOWIDTH, VIDEOHEIGHT, VIDEOBITSPERPIXEL, panzp);
|
|||
|
|
}
|
|||
|
|
public Image img;
|
|||
|
|
private void FrmPaiZhao_Load(object sender, EventArgs e)
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
IntPtr m_ip = IntPtr.Zero;
|
|||
|
|
private void button1_Click(object sender, EventArgs e)
|
|||
|
|
{
|
|||
|
|
Cursor.Current = Cursors.WaitCursor;
|
|||
|
|
|
|||
|
|
// Release any previous buffer
|
|||
|
|
if (m_ip != IntPtr.Zero)
|
|||
|
|
{
|
|||
|
|
Marshal.FreeCoTaskMem(m_ip);
|
|||
|
|
m_ip = IntPtr.Zero;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// capture image
|
|||
|
|
m_ip = cam.Click();
|
|||
|
|
Bitmap b = new Bitmap(cam.Width, cam.Height, cam.Stride, PixelFormat.Format24bppRgb, m_ip);
|
|||
|
|
|
|||
|
|
// If the image is upsidedown
|
|||
|
|
b.RotateFlip(RotateFlipType.RotateNoneFlipY);
|
|||
|
|
img = b;
|
|||
|
|
|
|||
|
|
Cursor.Current = Cursors.Default;
|
|||
|
|
DialogResult = DialogResult.OK;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void FrmPaiZhao_FormClosed(object sender, FormClosedEventArgs e)
|
|||
|
|
{
|
|||
|
|
cam.Dispose();
|
|||
|
|
|
|||
|
|
if (m_ip != IntPtr.Zero)
|
|||
|
|
{
|
|||
|
|
Marshal.FreeCoTaskMem(m_ip);
|
|||
|
|
m_ip = IntPtr.Zero;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|