zoukankan      html  css  js  c++  java
  • 视频播放时抓图

      


    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 窗体设计器生成的代码

            
    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, 
    320240, fBitmapName+".bmp" );      
                   img 
    = Image.FromFile( fBitmapName + ".bmp" );
                   img.Save( fBitmapName 
    + ".jpg", ImageFormat.Jpeg );
                   img.Dispose();
                   System.IO.File.Delete( fBitmapName 
    + ".bmp" );        
                    
                }

        



        }

    }



    效果为


  • 相关阅读:
    删除文件时,提示 "操作无法完成..." 怎么处理
    对象的理解
    TP5架构下链接SQL数据库的一种方法
    关于URL隐藏index.php方法
    非典型的千万用户后台之路
    就这样,再见2015
    理想的程序员
    4个小例子告诉你:如何成为一名数据极客
    馆中窥职:小公司没那么糟糕
    JAVA设计模式详解(六)----------状态模式
  • 原文地址:https://www.cnblogs.com/gwazy/p/535871.html
Copyright © 2011-2022 走看看