using
System ;
using System.Drawing ;
using System.Collections ;
using System.ComponentModel ;
using System.Windows.Forms ;
using System.Data ;
using Microsoft.DirectX.AudioVideoPlayback ;
using System.IO;
using System.Threading;
using System.Runtime.InteropServices;
using System.Drawing.Imaging;
using DexterLib;
namespace abc
{
/**//// <summary>
/// Form2 的摘要说明。
/// </summary>
public class Form2 : System.Windows.Forms.Form
{
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.OpenFileDialog openFileDialog1;
private Video MyVideo = null ;
private System.Windows.Forms.Timer timer1;
private System.Windows.Forms.Label label1;
private System.ComponentModel.IContainer components;
public Form2()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/**//// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
Windows 窗体设计器生成的代码#region Windows 窗体设计器生成的代码
/**//// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.panel1 = new System.Windows.Forms.Panel();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
this.timer1 = new System.Windows.Forms.Timer(this.components);
this.label1 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// panel1
//
this.panel1.Dock = System.Windows.Forms.DockStyle.Top;
this.panel1.Location = new System.Drawing.Point(0, 0);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(292, 176);
this.panel1.TabIndex = 0;
//
// button1
//
this.button1.Location = new System.Drawing.Point(32, 216);
this.button1.Name = "button1";
this.button1.TabIndex = 1;
this.button1.Text = "打开";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(120, 216);
this.button2.Name = "button2";
this.button2.TabIndex = 2;
this.button2.Text = "抓图";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// openFileDialog1
//
this.openFileDialog1.FileOk += new System.ComponentModel.CancelEventHandler(this.openFileDialog1_FileOk);
//
// timer1
//
this.timer1.Enabled = true;
this.timer1.Interval = 1000;
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
//
// label1
//
this.label1.Location = new System.Drawing.Point(216, 216);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(72, 23);
this.label1.TabIndex = 3;
this.label1.Text = "label1";
//
// Form2
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.Add(this.label1);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Controls.Add(this.panel1);
this.Name = "Form2";
this.Text = "Form2";
this.ResumeLayout(false);
}
#endregion
private void button1_Click(object sender, System.EventArgs e)
{ int height = panel1.Height ;
int width = panel1.Width ;
openFileDialog1.InitialDirectory = Application.StartupPath ;
if (this.openFileDialog1 .ShowDialog() ==DialogResult.OK)
{
if ( MyVideo != null )
{
MyVideo.Dispose ( ) ;
}
MyVideo = new Video ( openFileDialog1.FileName ) ;
MyVideo.Owner = panel1 ;
panel1.Width = width ;
panel1.Height = height ;
MyVideo.Play();
}
}
private void timer1_Tick(object sender, System.EventArgs e)
{
if (MyVideo!=null)
{
this.label1 .Text =MyVideo.CurrentPosition.ToString ();
}
}
private void openFileDialog1_FileOk(object sender, System.ComponentModel.CancelEventArgs e)
{
}
private void button2_Click(object sender, System.EventArgs e)
{
this.Scan(MyVideo.CurrentPosition ,this.openFileDialog1.FileName );
}
void Scan(double tempid ,string filename)
{ MediaDetClass md;
md = new MediaDetClass();
Image img;
md.Filename = filename;
string fBitmapName=System.DateTime.Now.ToString ("yyyyMMddhhmmss");
md.WriteBitmapBits( tempid, 320, 240, fBitmapName+".bmp" );
img = Image.FromFile( fBitmapName + ".bmp" );
img.Save( fBitmapName + ".jpg", ImageFormat.Jpeg );
img.Dispose();
System.IO.File.Delete( fBitmapName + ".bmp" );
}
}
}
using System.Drawing ;
using System.Collections ;
using System.ComponentModel ;
using System.Windows.Forms ;
using System.Data ;
using Microsoft.DirectX.AudioVideoPlayback ;
using System.IO;
using System.Threading;
using System.Runtime.InteropServices;
using System.Drawing.Imaging;
using DexterLib;
namespace abc
{
/**//// <summary>
/// Form2 的摘要说明。
/// </summary>
public class Form2 : System.Windows.Forms.Form
{
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.OpenFileDialog openFileDialog1;
private Video MyVideo = null ;
private System.Windows.Forms.Timer timer1;
private System.Windows.Forms.Label label1;
private System.ComponentModel.IContainer components;
public Form2()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/**//// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
Windows 窗体设计器生成的代码#region Windows 窗体设计器生成的代码
/**//// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.panel1 = new System.Windows.Forms.Panel();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
this.timer1 = new System.Windows.Forms.Timer(this.components);
this.label1 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// panel1
//
this.panel1.Dock = System.Windows.Forms.DockStyle.Top;
this.panel1.Location = new System.Drawing.Point(0, 0);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(292, 176);
this.panel1.TabIndex = 0;
//
// button1
//
this.button1.Location = new System.Drawing.Point(32, 216);
this.button1.Name = "button1";
this.button1.TabIndex = 1;
this.button1.Text = "打开";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(120, 216);
this.button2.Name = "button2";
this.button2.TabIndex = 2;
this.button2.Text = "抓图";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// openFileDialog1
//
this.openFileDialog1.FileOk += new System.ComponentModel.CancelEventHandler(this.openFileDialog1_FileOk);
//
// timer1
//
this.timer1.Enabled = true;
this.timer1.Interval = 1000;
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
//
// label1
//
this.label1.Location = new System.Drawing.Point(216, 216);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(72, 23);
this.label1.TabIndex = 3;
this.label1.Text = "label1";
//
// Form2
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.Add(this.label1);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Controls.Add(this.panel1);
this.Name = "Form2";
this.Text = "Form2";
this.ResumeLayout(false);
}
#endregion
private void button1_Click(object sender, System.EventArgs e)
{ int height = panel1.Height ;
int width = panel1.Width ;
openFileDialog1.InitialDirectory = Application.StartupPath ;
if (this.openFileDialog1 .ShowDialog() ==DialogResult.OK)
{
if ( MyVideo != null )
{
MyVideo.Dispose ( ) ;
}
MyVideo = new Video ( openFileDialog1.FileName ) ;
MyVideo.Owner = panel1 ;
panel1.Width = width ;
panel1.Height = height ;
MyVideo.Play();
}
}
private void timer1_Tick(object sender, System.EventArgs e)
{
if (MyVideo!=null)
{
this.label1 .Text =MyVideo.CurrentPosition.ToString ();
}
}
private void openFileDialog1_FileOk(object sender, System.ComponentModel.CancelEventArgs e)
{
}
private void button2_Click(object sender, System.EventArgs e)
{
this.Scan(MyVideo.CurrentPosition ,this.openFileDialog1.FileName );
}
void Scan(double tempid ,string filename)
{ MediaDetClass md;
md = new MediaDetClass();
Image img;
md.Filename = filename;
string fBitmapName=System.DateTime.Now.ToString ("yyyyMMddhhmmss");
md.WriteBitmapBits( tempid, 320, 240, fBitmapName+".bmp" );
img = Image.FromFile( fBitmapName + ".bmp" );
img.Save( fBitmapName + ".jpg", ImageFormat.Jpeg );
img.Dispose();
System.IO.File.Delete( fBitmapName + ".bmp" );
}
}
}
效果为