用C#预览视频文件(简略)
我的IR项目里要对视频文件进行预览,目前还没有解决,以下的方法是一个尝试。
在system32下,有一个qedit.dll文件,这是DirectShow的一个COM组件(DS大部份都是COM组件),就是说我们可以直接以COM的形式引用到C#项目里。
我做了一个简单测试项目。先把qedit.dll找到,然后以COM注册到项目中。对MediaDet类进行了一个简单的封装,然后运行一个测试项目:
运行结果(从AVI中提取第10桢的内容):
部份代码:仅供参考:

 MediaDetector类
MediaDetector类 using System;
using System; using System.IO;
using System.IO; using DexterLib;
using DexterLib; using System.Drawing;
using System.Drawing; using System.Drawing.Imaging;
using System.Drawing.Imaging;
 namespace PublicLibrary
namespace PublicLibrary

 {
{
 /**//// <summary>
    /**//// <summary> /// Summary description for MediaDetector.
    /// Summary description for MediaDetector. /// </summary>
    /// </summary> public class MediaDetector
    public class MediaDetector
 
     {
{ //fields
        //fields protected MediaDetClass _MediaDet;
        protected MediaDetClass _MediaDet; protected Image.GetThumbnailImageAbort _ImageCallback;
        protected Image.GetThumbnailImageAbort _ImageCallback; //events
        //events public event ErrorHandler OnError;
        public event ErrorHandler OnError; //properties
        //properties protected MediaDetClass MediaDecteor
        protected MediaDetClass MediaDecteor
 
         {
{ get
            get
 
             {
{ if(this._MediaDet==null)
                if(this._MediaDet==null)
 
                 {
{ try
                    try
 
                     {
{ this._MediaDet = new MediaDetClass();
                        this._MediaDet = new MediaDetClass(); }
                    } catch(Exception ex)
                    catch(Exception ex)
 
                     {
{ this.FileErrorEvent(ex);
                        this.FileErrorEvent(ex); }
                    } }
                } return _MediaDet;
                return _MediaDet; }
            } }
        } protected Image.GetThumbnailImageAbort ImageCallback
        protected Image.GetThumbnailImageAbort ImageCallback
 
         {
{ get
            get
 
             {
{ if(this._ImageCallback == null)
                if(this._ImageCallback == null)
 
                 {
{ this._ImageCallback = new Image.GetThumbnailImageAbort(ThumbnailCallback);
                    this._ImageCallback = new Image.GetThumbnailImageAbort(ThumbnailCallback); }
                } return this._ImageCallback;
                return this._ImageCallback; }
            } }
        }
 //methods
        //methods private void FileErrorEvent(Exception i_ex)
        private void FileErrorEvent(Exception i_ex)
 
         {
{ if(this.OnError!=null)
            if(this.OnError!=null)
 
             {
{ try
                try
 
                 {
{ this.OnError(this,i_ex);
                    this.OnError(this,i_ex); }
                } catch(Exception ex)
                catch(Exception ex)
 
                 {
{ System.Diagnostics.Trace.WriteLine(ex.Message);
                    System.Diagnostics.Trace.WriteLine(ex.Message); }
                } }
            } }
        }
 /**//// <summary>
        /**//// <summary> /// Method to get thumbinal image from media file.
        /// Method to get thumbinal image from media file. /// </summary>
        /// </summary> /// <param name="i_MediaFile">Media file full path and name.</param>
        /// <param name="i_MediaFile">Media file full path and name.</param> /// <param name="i_Size">Image size.</param>
        /// <param name="i_Size">Image size.</param> /// <param name="i_type">Media type</param>
        /// <param name="i_type">Media type</param> /// <param name="i_Stream">If the media type is video, this parameter is the video's stream to grab and create image.</param>
        /// <param name="i_Stream">If the media type is video, this parameter is the video's stream to grab and create image.</param> /// <returns></returns>
        /// <returns></returns> public Image GetThumbnail(string i_MediaFile,Size i_Size,MediaTypes i_type,int i_Stream)
        public Image GetThumbnail(string i_MediaFile,Size i_Size,MediaTypes i_type,int i_Stream)
 
         {
{ switch(i_type)
            switch(i_type)
 
             {
{ default:
                default: case MediaTypes.Unknow:
                case MediaTypes.Unknow: this.FileErrorEvent(new Exception("Unknow media type."));
                    this.FileErrorEvent(new Exception("Unknow media type.")); return null;
                    return null; case MediaTypes.Audio:
                case MediaTypes.Audio: this.FileErrorEvent(new Exception("This media type has not implemented to create an image."));
                    this.FileErrorEvent(new Exception("This media type has not implemented to create an image.")); return null;
                    return null; case MediaTypes.Image:
                case MediaTypes.Image: return this.GetThumbnailFromImage(i_MediaFile,i_Size);
                    return this.GetThumbnailFromImage(i_MediaFile,i_Size); case MediaTypes.Video:
                case MediaTypes.Video: return this.GetThumbnailFromVideo(i_MediaFile,i_Size,i_Stream);
                    return this.GetThumbnailFromVideo(i_MediaFile,i_Size,i_Stream); }
            } }
        }
 public Image GetThumbnailFromImage(string i_MediaFile,Size i_Size)
        public Image GetThumbnailFromImage(string i_MediaFile,Size i_Size)
 
         {
{ try
            try
 
             {
{ Image m_image = Image.FromFile(i_MediaFile);
                Image m_image = Image.FromFile(i_MediaFile); return m_image.GetThumbnailImage(i_Size.Width,i_Size.Height,this.ImageCallback,IntPtr.Zero);
                return m_image.GetThumbnailImage(i_Size.Width,i_Size.Height,this.ImageCallback,IntPtr.Zero); }
            } catch(Exception ex)
            catch(Exception ex)
 
             {
{ this.FileErrorEvent(ex);
                this.FileErrorEvent(ex); return null;
                return null; }
            } }
        }
 public Image GetThumbnailFromVideo(string i_MediaFile,Size i_Size,int i_Stream)
        public Image GetThumbnailFromVideo(string i_MediaFile,Size i_Size,int i_Stream)
 
         {
{ this.MediaDecteor.Filename = i_MediaFile;
            this.MediaDecteor.Filename = i_MediaFile; this.MediaDecteor.CurrentStream = 0;
            this.MediaDecteor.CurrentStream = 0; //int m_ImageSize = (int)this.MediaDecteor.StreamLength;
            //int m_ImageSize = (int)this.MediaDecteor.StreamLength; try
            try
 
             {
{ this.MediaDecteor.WriteBitmapBits(i_Stream,i_Size.Width,i_Size.Height,"Temp.bmp");
                this.MediaDecteor.WriteBitmapBits(i_Stream,i_Size.Width,i_Size.Height,"Temp.bmp"); Stream m_stream = File.Open("Temp.bmp",FileMode.Open,FileAccess.Read,FileShare.None);
                Stream m_stream = File.Open("Temp.bmp",FileMode.Open,FileAccess.Read,FileShare.None); byte[] m_bytes = new byte[m_stream.Length];
                byte[] m_bytes = new byte[m_stream.Length]; m_stream.Read(m_bytes,0,m_bytes.Length);
                m_stream.Read(m_bytes,0,m_bytes.Length); m_stream.Close();
                m_stream.Close(); File.Delete("Temp.bmp");
                File.Delete("Temp.bmp"); MemoryStream m_MemoStream = new MemoryStream(m_bytes.Length);
                MemoryStream m_MemoStream = new MemoryStream(m_bytes.Length); m_MemoStream.Write(m_bytes,0,m_bytes.Length);
                m_MemoStream.Write(m_bytes,0,m_bytes.Length); return Image.FromStream(m_MemoStream);
                return Image.FromStream(m_MemoStream); }
            } catch(Exception ex)
            catch(Exception ex)
 
             {
{ this.FileErrorEvent(ex);
                this.FileErrorEvent(ex); return null;
                return null; }
            } }
        }
 private bool ThumbnailCallback()
        private bool ThumbnailCallback()
 
         {
{ return false;
            return false; }
        } //ctor
        //ctor public MediaDetector()
        public MediaDetector()
 
         {
{             }
        } }
    }

 public class MediaHelper#region public class MediaHelper
    public class MediaHelper#region public class MediaHelper public class MediaHelper
    public class MediaHelper
 
     {
{ static public MediaTypes ConvertToMediaType(int i_Type)
        static public MediaTypes ConvertToMediaType(int i_Type)
 
         {
{ switch(i_Type)
            switch(i_Type)
 
             {
{ default:
                default: case 0:
                case 0: return MediaTypes.Unknow;
                    return MediaTypes.Unknow; case 1:
                case 1: return MediaTypes.Image;
                    return MediaTypes.Image; case 2:
                case 2: return MediaTypes.Video;
                    return MediaTypes.Video; case 3:
                case 3: return MediaTypes.Audio;
                    return MediaTypes.Audio; }
            } }
        }
 static public MediaTypes ConvertToMediaType(string i_Type)
        static public MediaTypes ConvertToMediaType(string i_Type)
 
         {
{ switch(i_Type.ToLower())
            switch(i_Type.ToLower())
 
             {
{ default:
                default: case "unknow":
                case "unknow": return MediaTypes.Unknow;
                    return MediaTypes.Unknow; case "image":
                case "image": return MediaTypes.Image;
                    return MediaTypes.Image; case "video":
                case "video": return MediaTypes.Video;
                    return MediaTypes.Video; case "audio":
                case "audio": return MediaTypes.Audio;
                    return MediaTypes.Audio; }
            } }
        } }
    } #endregion
    #endregion
 public delegate void ErrorHandler(object i_Sender,Exception i_ex);
    public delegate void ErrorHandler(object i_Sender,Exception i_ex); public enum MediaTypes
    public enum MediaTypes
 
     {
{ Image = 1,
        Image = 1, Video = 2,
        Video = 2, Audio = 3,
        Audio = 3, Unknow = 0,
        Unknow = 0, }
    }
 }
}
测试Form代码:

 Form类
Form类 using System;
using System; using System.Drawing;
using System.Drawing; using System.Collections;
using System.Collections; using System.ComponentModel;
using System.ComponentModel; using System.Windows.Forms;
using System.Windows.Forms; //
// using PublicLibrary;
using PublicLibrary;
 namespace Country.Study
namespace Country.Study

 {
{
 /**//// <summary>
    /**//// <summary> /// Summary description for Thumbinal.
    /// Summary description for Thumbinal. /// </summary>
    /// </summary> public class Thumbnail : System.Windows.Forms.Form
    public class Thumbnail : System.Windows.Forms.Form
 
     {
{ private MediaDetector _MediaDetector;
        private MediaDetector _MediaDetector; //
        // private MediaDetector MediaDetector
        private MediaDetector MediaDetector
 
         {
{ get
            get
 
             {
{                 return this._MediaDetector;
                return this._MediaDetector; }
            } }
        } //
        // private System.Windows.Forms.StatusBar statusBar1;
        private System.Windows.Forms.StatusBar statusBar1; private System.Windows.Forms.Panel panel1;
        private System.Windows.Forms.Panel panel1; private System.Windows.Forms.TextBox C_Path;
        private System.Windows.Forms.TextBox C_Path; private System.Windows.Forms.Button C_Browse;
        private System.Windows.Forms.Button C_Browse; private System.Windows.Forms.Panel panel2;
        private System.Windows.Forms.Panel panel2; private System.Windows.Forms.Label C_LabWidth;
        private System.Windows.Forms.Label C_LabWidth; private System.Windows.Forms.TextBox C_Width;
        private System.Windows.Forms.TextBox C_Width; private System.Windows.Forms.Label C_LabHeight;
        private System.Windows.Forms.Label C_LabHeight; private System.Windows.Forms.TextBox C_Height;
        private System.Windows.Forms.TextBox C_Height; private System.Windows.Forms.Label C_LabType;
        private System.Windows.Forms.Label C_LabType; private System.Windows.Forms.ComboBox C_MediaTypes;
        private System.Windows.Forms.ComboBox C_MediaTypes; private System.Windows.Forms.Label C_LabStream;
        private System.Windows.Forms.Label C_LabStream; private System.Windows.Forms.Button C_Create;
        private System.Windows.Forms.Button C_Create; private System.Windows.Forms.OpenFileDialog C_OpenFileDialog;
        private System.Windows.Forms.OpenFileDialog C_OpenFileDialog; private System.Windows.Forms.TextBox C_Stream;
        private System.Windows.Forms.TextBox C_Stream; private System.Windows.Forms.PictureBox C_PicBox;
        private System.Windows.Forms.PictureBox C_PicBox;
 /**//// <summary>
        /**//// <summary> /// Required designer variable.
        /// Required designer variable. /// </summary>
        /// </summary> private System.ComponentModel.Container components = null;
        private System.ComponentModel.Container components = null;
 public Thumbnail()
        public Thumbnail()
 
         {
{ //
            // // Required for Windows Form Designer support
            // Required for Windows Form Designer support //
            // InitializeComponent();
            InitializeComponent();
 //
            // // TODO: Add any constructor code after InitializeComponent call
            // TODO: Add any constructor code after InitializeComponent call //
            // this._MediaDetector = new MediaDetector();
            this._MediaDetector = new MediaDetector(); this._MediaDetector.OnError += new ErrorHandler(MediaDetector_OnError);
            this._MediaDetector.OnError += new ErrorHandler(MediaDetector_OnError); }
        }

 /**//// <summary>
        /**//// <summary> /// Clean up any resources being used.
        /// Clean up any resources being used. /// </summary>
        /// </summary> protected override void Dispose( bool disposing )
        protected override void Dispose( bool disposing )
 
         {
{ if(this._MediaDetector!=null)
            if(this._MediaDetector!=null)
 
             {
{ this._MediaDetector.OnError -= new ErrorHandler(MediaDetector_OnError);
                this._MediaDetector.OnError -= new ErrorHandler(MediaDetector_OnError); this._MediaDetector = null;
                this._MediaDetector = null; }
            } if( disposing )
            if( disposing )
 
             {
{ if(components != null)
                if(components != null)
 
                 {
{ components.Dispose();
                    components.Dispose(); }
                } }
            } base.Dispose( disposing );
            base.Dispose( disposing ); }
        }

 Windows Form Designer generated code#region Windows Form Designer generated code
        Windows Form Designer generated code#region Windows Form Designer generated code
 /**//// <summary>
        /**//// <summary> /// Required method for Designer support - do not modify
        /// Required method for Designer support - do not modify /// the contents of this method with the code editor.
        /// the contents of this method with the code editor. /// </summary>
        /// </summary> private void InitializeComponent()
        private void InitializeComponent()
 
         {
{ this.statusBar1 = new System.Windows.Forms.StatusBar();
            this.statusBar1 = new System.Windows.Forms.StatusBar(); this.panel1 = new System.Windows.Forms.Panel();
            this.panel1 = new System.Windows.Forms.Panel(); this.C_Browse = new System.Windows.Forms.Button();
            this.C_Browse = new System.Windows.Forms.Button(); this.C_Path = new System.Windows.Forms.TextBox();
            this.C_Path = new System.Windows.Forms.TextBox(); this.panel2 = new System.Windows.Forms.Panel();
            this.panel2 = new System.Windows.Forms.Panel(); this.C_Create = new System.Windows.Forms.Button();
            this.C_Create = new System.Windows.Forms.Button(); this.C_Stream = new System.Windows.Forms.TextBox();
            this.C_Stream = new System.Windows.Forms.TextBox(); this.C_LabStream = new System.Windows.Forms.Label();
            this.C_LabStream = new System.Windows.Forms.Label(); this.C_MediaTypes = new System.Windows.Forms.ComboBox();
            this.C_MediaTypes = new System.Windows.Forms.ComboBox(); this.C_LabType = new System.Windows.Forms.Label();
            this.C_LabType = new System.Windows.Forms.Label(); this.C_Height = new System.Windows.Forms.TextBox();
            this.C_Height = new System.Windows.Forms.TextBox(); this.C_LabHeight = new System.Windows.Forms.Label();
            this.C_LabHeight = new System.Windows.Forms.Label(); this.C_LabWidth = new System.Windows.Forms.Label();
            this.C_LabWidth = new System.Windows.Forms.Label(); this.C_Width = new System.Windows.Forms.TextBox();
            this.C_Width = new System.Windows.Forms.TextBox(); this.C_PicBox = new System.Windows.Forms.PictureBox();
            this.C_PicBox = new System.Windows.Forms.PictureBox(); this.C_OpenFileDialog = new System.Windows.Forms.OpenFileDialog();
            this.C_OpenFileDialog = new System.Windows.Forms.OpenFileDialog(); this.panel1.SuspendLayout();
            this.panel1.SuspendLayout(); this.panel2.SuspendLayout();
            this.panel2.SuspendLayout(); this.SuspendLayout();
            this.SuspendLayout(); //
            //  // statusBar1
            // statusBar1 //
            //  this.statusBar1.Location = new System.Drawing.Point(0, 391);
            this.statusBar1.Location = new System.Drawing.Point(0, 391); this.statusBar1.Name = "statusBar1";
            this.statusBar1.Name = "statusBar1"; this.statusBar1.Size = new System.Drawing.Size(568, 22);
            this.statusBar1.Size = new System.Drawing.Size(568, 22); this.statusBar1.TabIndex = 0;
            this.statusBar1.TabIndex = 0; this.statusBar1.Text = "statusBar1";
            this.statusBar1.Text = "statusBar1"; //
            //  // panel1
            // panel1 //
            //  this.panel1.Controls.Add(this.C_Browse);
            this.panel1.Controls.Add(this.C_Browse); this.panel1.Controls.Add(this.C_Path);
            this.panel1.Controls.Add(this.C_Path); this.panel1.Dock = System.Windows.Forms.DockStyle.Top;
            this.panel1.Dock = System.Windows.Forms.DockStyle.Top; this.panel1.Location = new System.Drawing.Point(0, 0);
            this.panel1.Location = new System.Drawing.Point(0, 0); this.panel1.Name = "panel1";
            this.panel1.Name = "panel1"; this.panel1.Size = new System.Drawing.Size(568, 40);
            this.panel1.Size = new System.Drawing.Size(568, 40); this.panel1.TabIndex = 1;
            this.panel1.TabIndex = 1; //
            //  // C_Browse
            // C_Browse //
            //  this.C_Browse.Location = new System.Drawing.Point(480, 8);
            this.C_Browse.Location = new System.Drawing.Point(480, 8); this.C_Browse.Name = "C_Browse";
            this.C_Browse.Name = "C_Browse"; this.C_Browse.TabIndex = 1;
            this.C_Browse.TabIndex = 1; this.C_Browse.Text = "Browse
            this.C_Browse.Text = "Browse ";
"; this.C_Browse.Click += new System.EventHandler(this.C_Browse_Click);
            this.C_Browse.Click += new System.EventHandler(this.C_Browse_Click); //
            //  // C_Path
            // C_Path //
            //  this.C_Path.Location = new System.Drawing.Point(8, 8);
            this.C_Path.Location = new System.Drawing.Point(8, 8); this.C_Path.Name = "C_Path";
            this.C_Path.Name = "C_Path"; this.C_Path.ReadOnly = true;
            this.C_Path.ReadOnly = true; this.C_Path.Size = new System.Drawing.Size(464, 20);
            this.C_Path.Size = new System.Drawing.Size(464, 20); this.C_Path.TabIndex = 0;
            this.C_Path.TabIndex = 0; this.C_Path.Text = "textBox1";
            this.C_Path.Text = "textBox1"; //
            //  // panel2
            // panel2 //
            //  this.panel2.Controls.Add(this.C_Create);
            this.panel2.Controls.Add(this.C_Create); this.panel2.Controls.Add(this.C_Stream);
            this.panel2.Controls.Add(this.C_Stream); this.panel2.Controls.Add(this.C_LabStream);
            this.panel2.Controls.Add(this.C_LabStream); this.panel2.Controls.Add(this.C_MediaTypes);
            this.panel2.Controls.Add(this.C_MediaTypes); this.panel2.Controls.Add(this.C_LabType);
            this.panel2.Controls.Add(this.C_LabType); this.panel2.Controls.Add(this.C_Height);
            this.panel2.Controls.Add(this.C_Height); this.panel2.Controls.Add(this.C_LabHeight);
            this.panel2.Controls.Add(this.C_LabHeight); this.panel2.Controls.Add(this.C_LabWidth);
            this.panel2.Controls.Add(this.C_LabWidth); this.panel2.Controls.Add(this.C_Width);
            this.panel2.Controls.Add(this.C_Width); this.panel2.Dock = System.Windows.Forms.DockStyle.Left;
            this.panel2.Dock = System.Windows.Forms.DockStyle.Left; this.panel2.Location = new System.Drawing.Point(0, 40);
            this.panel2.Location = new System.Drawing.Point(0, 40); this.panel2.Name = "panel2";
            this.panel2.Name = "panel2"; this.panel2.Size = new System.Drawing.Size(176, 351);
            this.panel2.Size = new System.Drawing.Size(176, 351); this.panel2.TabIndex = 2;
            this.panel2.TabIndex = 2; //
            //  // C_Create
            // C_Create //
            //  this.C_Create.Location = new System.Drawing.Point(8, 136);
            this.C_Create.Location = new System.Drawing.Point(8, 136); this.C_Create.Name = "C_Create";
            this.C_Create.Name = "C_Create"; this.C_Create.Size = new System.Drawing.Size(152, 23);
            this.C_Create.Size = new System.Drawing.Size(152, 23); this.C_Create.TabIndex = 10;
            this.C_Create.TabIndex = 10; this.C_Create.Text = "Create Thumbnail Image";
            this.C_Create.Text = "Create Thumbnail Image"; this.C_Create.Click += new System.EventHandler(this.C_Create_Click);
            this.C_Create.Click += new System.EventHandler(this.C_Create_Click); //
            //  // C_Stream
            // C_Stream //
            //  this.C_Stream.Location = new System.Drawing.Point(64, 104);
            this.C_Stream.Location = new System.Drawing.Point(64, 104); this.C_Stream.Name = "C_Stream";
            this.C_Stream.Name = "C_Stream"; this.C_Stream.TabIndex = 9;
            this.C_Stream.TabIndex = 9; this.C_Stream.Text = "1";
            this.C_Stream.Text = "1"; //
            //  // C_LabStream
            // C_LabStream //
            //  this.C_LabStream.Location = new System.Drawing.Point(8, 104);
            this.C_LabStream.Location = new System.Drawing.Point(8, 104); this.C_LabStream.Name = "C_LabStream";
            this.C_LabStream.Name = "C_LabStream"; this.C_LabStream.Size = new System.Drawing.Size(56, 16);
            this.C_LabStream.Size = new System.Drawing.Size(56, 16); this.C_LabStream.TabIndex = 8;
            this.C_LabStream.TabIndex = 8; this.C_LabStream.Text = "Stream";
            this.C_LabStream.Text = "Stream"; //
            //  // C_MediaTypes
            // C_MediaTypes //
            // 
 this.C_MediaTypes.Items.AddRange(new object[]
            this.C_MediaTypes.Items.AddRange(new object[]  {
{ "Unknow",
                                                              "Unknow", "Image",
                                                              "Image", "Audio",
                                                              "Audio", "Video"});
                                                              "Video"}); this.C_MediaTypes.Location = new System.Drawing.Point(64, 72);
            this.C_MediaTypes.Location = new System.Drawing.Point(64, 72); this.C_MediaTypes.Name = "C_MediaTypes";
            this.C_MediaTypes.Name = "C_MediaTypes"; this.C_MediaTypes.Size = new System.Drawing.Size(104, 21);
            this.C_MediaTypes.Size = new System.Drawing.Size(104, 21); this.C_MediaTypes.TabIndex = 7;
            this.C_MediaTypes.TabIndex = 7; //
            //  // C_LabType
            // C_LabType //
            //  this.C_LabType.Location = new System.Drawing.Point(8, 72);
            this.C_LabType.Location = new System.Drawing.Point(8, 72); this.C_LabType.Name = "C_LabType";
            this.C_LabType.Name = "C_LabType"; this.C_LabType.Size = new System.Drawing.Size(56, 16);
            this.C_LabType.Size = new System.Drawing.Size(56, 16); this.C_LabType.TabIndex = 6;
            this.C_LabType.TabIndex = 6; this.C_LabType.Text = "Type";
            this.C_LabType.Text = "Type"; //
            //  // C_Height
            // C_Height //
            //  this.C_Height.Location = new System.Drawing.Point(64, 40);
            this.C_Height.Location = new System.Drawing.Point(64, 40); this.C_Height.Name = "C_Height";
            this.C_Height.Name = "C_Height"; this.C_Height.TabIndex = 5;
            this.C_Height.TabIndex = 5; this.C_Height.Text = "300";
            this.C_Height.Text = "300"; //
            //  // C_LabHeight
            // C_LabHeight //
            //  this.C_LabHeight.Location = new System.Drawing.Point(8, 40);
            this.C_LabHeight.Location = new System.Drawing.Point(8, 40); this.C_LabHeight.Name = "C_LabHeight";
            this.C_LabHeight.Name = "C_LabHeight"; this.C_LabHeight.Size = new System.Drawing.Size(56, 16);
            this.C_LabHeight.Size = new System.Drawing.Size(56, 16); this.C_LabHeight.TabIndex = 4;
            this.C_LabHeight.TabIndex = 4; this.C_LabHeight.Text = "Height";
            this.C_LabHeight.Text = "Height"; //
            //  // C_LabWidth
            // C_LabWidth //
            //  this.C_LabWidth.Location = new System.Drawing.Point(8, 8);
            this.C_LabWidth.Location = new System.Drawing.Point(8, 8); this.C_LabWidth.Name = "C_LabWidth";
            this.C_LabWidth.Name = "C_LabWidth"; this.C_LabWidth.Size = new System.Drawing.Size(56, 16);
            this.C_LabWidth.Size = new System.Drawing.Size(56, 16); this.C_LabWidth.TabIndex = 3;
            this.C_LabWidth.TabIndex = 3; this.C_LabWidth.Text = "Width";
            this.C_LabWidth.Text = "Width"; //
            //  // C_Width
            // C_Width //
            //  this.C_Width.Location = new System.Drawing.Point(64, 8);
            this.C_Width.Location = new System.Drawing.Point(64, 8); this.C_Width.Name = "C_Width";
            this.C_Width.Name = "C_Width"; this.C_Width.TabIndex = 3;
            this.C_Width.TabIndex = 3; this.C_Width.Text = "300";
            this.C_Width.Text = "300"; //
            //  // C_PicBox
            // C_PicBox //
            //  this.C_PicBox.Location = new System.Drawing.Point(176, 40);
            this.C_PicBox.Location = new System.Drawing.Point(176, 40); this.C_PicBox.Name = "C_PicBox";
            this.C_PicBox.Name = "C_PicBox"; this.C_PicBox.Size = new System.Drawing.Size(392, 351);
            this.C_PicBox.Size = new System.Drawing.Size(392, 351); this.C_PicBox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
            this.C_PicBox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage; this.C_PicBox.TabIndex = 3;
            this.C_PicBox.TabIndex = 3; this.C_PicBox.TabStop = false;
            this.C_PicBox.TabStop = false; //
            //  // Thumbnail
            // Thumbnail //
            //  this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(568, 413);
            this.ClientSize = new System.Drawing.Size(568, 413); this.Controls.Add(this.C_PicBox);
            this.Controls.Add(this.C_PicBox); this.Controls.Add(this.panel2);
            this.Controls.Add(this.panel2); this.Controls.Add(this.panel1);
            this.Controls.Add(this.panel1); this.Controls.Add(this.statusBar1);
            this.Controls.Add(this.statusBar1); this.Name = "Thumbnail";
            this.Name = "Thumbnail"; this.Text = "Thumbinal";
            this.Text = "Thumbinal"; this.panel1.ResumeLayout(false);
            this.panel1.ResumeLayout(false); this.panel2.ResumeLayout(false);
            this.panel2.ResumeLayout(false); this.ResumeLayout(false);
            this.ResumeLayout(false);
 }
        } #endregion
        #endregion
 private void C_Create_Click(object sender, System.EventArgs e)
        private void C_Create_Click(object sender, System.EventArgs e)
 
         {
{ try
            try
 
             {
{ int m_width = Convert.ToInt32(this.C_Width.Text);
                int m_width = Convert.ToInt32(this.C_Width.Text); int m_height = Convert.ToInt32(this.C_Height.Text);
                int m_height = Convert.ToInt32(this.C_Height.Text); int m_stream = Convert.ToInt32(this.C_Stream.Text);
                int m_stream = Convert.ToInt32(this.C_Stream.Text); MediaTypes m_MediaType = MediaHelper.ConvertToMediaType(this.C_MediaTypes.SelectedItem.ToString());
                MediaTypes m_MediaType = MediaHelper.ConvertToMediaType(this.C_MediaTypes.SelectedItem.ToString()); Image m_image = this.MediaDetector.GetThumbnail(this.C_Path.Text,new Size(m_width,m_height),m_MediaType,m_stream);
                Image m_image = this.MediaDetector.GetThumbnail(this.C_Path.Text,new Size(m_width,m_height),m_MediaType,m_stream); this.C_PicBox.Image = m_image;
                this.C_PicBox.Image = m_image; this.C_PicBox.Width = m_width;
                this.C_PicBox.Width = m_width; this.C_PicBox.Height = m_height;
                this.C_PicBox.Height = m_height;                 this.C_PicBox.Refresh();
                this.C_PicBox.Refresh(); }
            } catch(Exception ex)
            catch(Exception ex)
 
             {
{ MessageBox.Show(string.Format("Error:{0}",ex.Message));
                MessageBox.Show(string.Format("Error:{0}",ex.Message)); }
            }         }
        }
 private void MediaDetector_OnError(object i_Sender, Exception i_ex)
        private void MediaDetector_OnError(object i_Sender, Exception i_ex)
 
         {
{ MessageBox.Show(this,string.Format("Create thumbnail image error. Message:{0}",i_ex.Message));
            MessageBox.Show(this,string.Format("Create thumbnail image error. Message:{0}",i_ex.Message)); }
        }
 private void C_Browse_Click(object sender, System.EventArgs e)
        private void C_Browse_Click(object sender, System.EventArgs e)
 
         {
{ if(this.C_OpenFileDialog.ShowDialog(this)==DialogResult.OK)
            if(this.C_OpenFileDialog.ShowDialog(this)==DialogResult.OK)
 
             {
{ this.C_Path.Text = this.C_OpenFileDialog.FileName;
                this.C_Path.Text = this.C_OpenFileDialog.FileName; }
            } }
        } }
    } }
}
仅做参考!
    ================================
/\_/\
(=^o^=) Wu.Country@侠缘
(~)@(~) 一辈子,用心做一件事!
--------------------------------
学而不思则罔,思而不学则怠!
================================
/\_/\
(=^o^=) Wu.Country@侠缘
(~)@(~) 一辈子,用心做一件事!
--------------------------------
学而不思则罔,思而不学则怠!
================================
posted on 2007-06-25 19:18 Wu.Country@侠缘 阅读(2096) 评论(5) 收藏 举报
 
                     
                    
                 
         
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号