视频播放时抓图

  


None.gif using  System ;
None.gif
using  System.Drawing ;
None.gif
using  System.Collections ;
None.gif
using  System.ComponentModel ;
None.gif
using  System.Windows.Forms ;
None.gif
using  System.Data ;
None.gif
using  Microsoft.DirectX.AudioVideoPlayback ;
None.gif
using  System.IO;
None.gif
using  System.Threading;
None.gif
using  System.Runtime.InteropServices;
None.gif
None.gif
using  System.Drawing.Imaging;
None.gif
None.gif
None.gif
using  DexterLib;
None.gif
None.gif
None.gif
namespace  abc
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//// 
InBlock.gif    
/// Form2 的摘要说明。
ExpandedSubBlockEnd.gif    
/// 

InBlock.gif    public class Form2 : System.Windows.Forms.Form
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
private System.Windows.Forms.Panel panel1;
InBlock.gif        
private System.Windows.Forms.Button button1;
InBlock.gif        
private System.Windows.Forms.Button button2;
InBlock.gif        
private System.Windows.Forms.OpenFileDialog openFileDialog1;
InBlock.gif
InBlock.gif        
private Video MyVideo = null ;
InBlock.gif        
private System.Windows.Forms.Timer timer1;
InBlock.gif        
private System.Windows.Forms.Label label1;
InBlock.gif        
private System.ComponentModel.IContainer components;
InBlock.gif        

InBlock.gif        
public Form2()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
//
InBlock.gif            
// Windows 窗体设计器支持所必需的
InBlock.gif            
//
InBlock.gif
            InitializeComponent();
InBlock.gif
InBlock.gif            
//
InBlock.gif            
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
InBlock.gif            
//
ExpandedSubBlockEnd.gif
        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// 
InBlock.gif        
/// 清理所有正在使用的资源。
ExpandedSubBlockEnd.gif        
/// 

InBlock.gif        protected override void Dispose( bool disposing )
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
if( disposing )
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if(components != null)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    components.Dispose();
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif            
base.Dispose( disposing );
ExpandedSubBlockEnd.gif        }

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif        
Windows 窗体设计器生成的代码#region Windows 窗体设计器生成的代码
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// 
InBlock.gif        
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
InBlock.gif        
/// 此方法的内容。
ExpandedSubBlockEnd.gif        
/// 

InBlock.gif        private void InitializeComponent()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
this.components = new System.ComponentModel.Container();
InBlock.gif            
this.panel1 = new System.Windows.Forms.Panel();
InBlock.gif            
this.button1 = new System.Windows.Forms.Button();
InBlock.gif            
this.button2 = new System.Windows.Forms.Button();
InBlock.gif            
this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
InBlock.gif            
this.timer1 = new System.Windows.Forms.Timer(this.components);
InBlock.gif            
this.label1 = new System.Windows.Forms.Label();
InBlock.gif            
this.SuspendLayout();
InBlock.gif            
// 
InBlock.gif            
// panel1
InBlock.gif            
// 
InBlock.gif
            this.panel1.Dock = System.Windows.Forms.DockStyle.Top;
InBlock.gif            
this.panel1.Location = new System.Drawing.Point(00);
InBlock.gif            
this.panel1.Name = "panel1";
InBlock.gif            
this.panel1.Size = new System.Drawing.Size(292176);
InBlock.gif            
this.panel1.TabIndex = 0;
InBlock.gif            
// 
InBlock.gif            
// button1
InBlock.gif            
// 
InBlock.gif
            this.button1.Location = new System.Drawing.Point(32216);
InBlock.gif            
this.button1.Name = "button1";
InBlock.gif            
this.button1.TabIndex = 1;
InBlock.gif            
this.button1.Text = "打开";
InBlock.gif            
this.button1.Click += new System.EventHandler(this.button1_Click);
InBlock.gif            
// 
InBlock.gif            
// button2
InBlock.gif            
// 
InBlock.gif
            this.button2.Location = new System.Drawing.Point(120216);
InBlock.gif            
this.button2.Name = "button2";
InBlock.gif            
this.button2.TabIndex = 2;
InBlock.gif            
this.button2.Text = "抓图";
InBlock.gif            
this.button2.Click += new System.EventHandler(this.button2_Click);
InBlock.gif            
// 
InBlock.gif            
// openFileDialog1
InBlock.gif            
// 
InBlock.gif
            this.openFileDialog1.FileOk += new System.ComponentModel.CancelEventHandler(this.openFileDialog1_FileOk);
InBlock.gif            
// 
InBlock.gif            
// timer1
InBlock.gif            
// 
InBlock.gif
            this.timer1.Enabled = true;
InBlock.gif            
this.timer1.Interval = 1000;
InBlock.gif            
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
InBlock.gif            
// 
InBlock.gif            
// label1
InBlock.gif            
// 
InBlock.gif
            this.label1.Location = new System.Drawing.Point(216216);
InBlock.gif            
this.label1.Name = "label1";
InBlock.gif            
this.label1.Size = new System.Drawing.Size(7223);
InBlock.gif            
this.label1.TabIndex = 3;
InBlock.gif            
this.label1.Text = "label1";
InBlock.gif            
// 
InBlock.gif            
// Form2
InBlock.gif            
// 
InBlock.gif
            this.AutoScaleBaseSize = new System.Drawing.Size(614);
InBlock.gif            
this.ClientSize = new System.Drawing.Size(292273);
InBlock.gif            
this.Controls.Add(this.label1);
InBlock.gif            
this.Controls.Add(this.button2);
InBlock.gif            
this.Controls.Add(this.button1);
InBlock.gif            
this.Controls.Add(this.panel1);
InBlock.gif            
this.Name = "Form2";
InBlock.gif            
this.Text = "Form2";
InBlock.gif            
this.ResumeLayout(false);
InBlock.gif
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
InBlock.gif        
private void button1_Click(object sender, System.EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{   int height = panel1.Height ;
InBlock.gif          
int width = panel1.Width ;
InBlock.gif            openFileDialog1.InitialDirectory 
= Application.StartupPath ;
InBlock.gif            
if (this.openFileDialog1 .ShowDialog() ==DialogResult.OK)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif    
InBlock.gif  
InBlock.gif               
if ( MyVideo != null ) 
ExpandedSubBlockStart.gifContractedSubBlock.gif                 
dot.gif{
InBlock.gif                 MyVideo.Dispose ( ) ;
ExpandedSubBlockEnd.gif                 }

InBlock.gif  
InBlock.gif             MyVideo 
= new Video ( openFileDialog1.FileName ) ; 
InBlock.gif 
InBlock.gif             MyVideo.Owner 
= panel1 ;
InBlock.gif 
InBlock.gif            panel1.Width 
= width ;
InBlock.gif            panel1.Height 
= height ;
InBlock.gif
InBlock.gif           MyVideo.Play();
InBlock.gif
InBlock.gif
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif            }

InBlock.gif
InBlock.gif        
private void timer1_Tick(object sender, System.EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{  
InBlock.gif            
if (MyVideo!=null)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
this.label1 .Text =MyVideo.CurrentPosition.ToString ();
InBlock.gif                  
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
private void openFileDialog1_FileOk(object sender, System.ComponentModel.CancelEventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif        
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
private void button2_Click(object sender, System.EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{       
InBlock.gif             
this.Scan(MyVideo.CurrentPosition ,this.openFileDialog1.FileName );
InBlock.gif        
InBlock.gif            
InBlock.gif            
InBlock.gif
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif
InBlock.gif
InBlock.gif            
void Scan(double tempid ,string filename) 
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{    MediaDetClass md;
InBlock.gif                md 
= new MediaDetClass();
InBlock.gif                Image img;
InBlock.gif                  md.Filename 
= filename;    
InBlock.gif                
InBlock.gif            
InBlock.gif               
InBlock.gif               
string fBitmapName=System.DateTime.Now.ToString ("yyyyMMddhhmmss");
InBlock.gif               md.WriteBitmapBits( tempid, 
320240, fBitmapName+".bmp" );      
InBlock.gif               img 
= Image.FromFile( fBitmapName + ".bmp" );
InBlock.gif               img.Save( fBitmapName 
+ ".jpg", ImageFormat.Jpeg );
InBlock.gif               img.Dispose();
InBlock.gif               System.IO.File.Delete( fBitmapName 
+ ".bmp" );        
InBlock.gif                
ExpandedSubBlockEnd.gif            }

InBlock.gif    
InBlock.gif
InBlock.gif
InBlock.gif
ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif


效果为


你可能感兴趣的:(视频播放时抓图)