我的IR项目里要对视频文件进行预览,目前还没有解决,以下的方法是一个尝试。
在system32下,有一个qedit.dll文件,这是DirectShow的一个COM组件(DS大部份都是COM组件),就是说我们可以直接以COM的形式引用到C#项目里。
我做了一个简单测试项目。先把qedit.dll找到,然后以COM注册到项目中。对MediaDet类进行了一个简单的封装,然后运行一个测试项目:
运行结果(从AVI中提取第10桢的内容):
部份代码:仅供参考:
MediaDetector类
using System;
using System.IO;
using DexterLib;
using System.Drawing;
using System.Drawing.Imaging;
namespace PublicLibrary
{
/**//// <summary>
/// Summary description for MediaDetector.
/// </summary>
public class MediaDetector
{
//fields
protected MediaDetClass _MediaDet;
protected Image.GetThumbnailImageAbort _ImageCallback;
//events
public event ErrorHandler OnError;
//properties
protected MediaDetClass MediaDecteor
{
get
{
if(this._MediaDet==null)
{
try
{
this._MediaDet = new MediaDetClass();
}
catch(Exception ex)
{
this.FileErrorEvent(ex);
}
}
return _MediaDet;
}
}
protected Image.GetThumbnailImageAbort ImageCallback
{
get
{
if(this._ImageCallback == null)
{
this._ImageCallback = new Image.GetThumbnailImageAbort(ThumbnailCallback);
}
return this._ImageCallback;
}
}
//methods
private void FileErrorEvent(Exception i_ex)
{
if(this.OnError!=null)
{
try
{
this.OnError(this,i_ex);
}
catch(Exception ex)
{
System.Diagnostics.Trace.WriteLine(ex.Message);
}
}
}
/**//// <summary>
/// Method to get thumbinal image from media file.
/// </summary>
/// <param name="i_MediaFile">Media file full path and name.</param>
/// <param name="i_Size">Image size.</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>
/// <returns></returns>
public Image GetThumbnail(string i_MediaFile,Size i_Size,MediaTypes i_type,int i_Stream)
{
switch(i_type)
{
default:
case MediaTypes.Unknow:
this.FileErrorEvent(new Exception("Unknow media type."));
return null;
case MediaTypes.Audio:
this.FileErrorEvent(new Exception("This media type has not implemented to create an image."));
return null;
case MediaTypes.Image:
return this.GetThumbnailFromImage(i_MediaFile,i_Size);
case MediaTypes.Video:
return this.GetThumbnailFromVideo(i_MediaFile,i_Size,i_Stream);
}
}
public Image GetThumbnailFromImage(string i_MediaFile,Size i_Size)
{
try
{
Image m_image = Image.FromFile(i_MediaFile);
return m_image.GetThumbnailImage(i_Size.Width,i_Size.Height,this.ImageCallback,IntPtr.Zero);
}
catch(Exception ex)
{
this.FileErrorEvent(ex);
return null;
}
}
public Image GetThumbnailFromVideo(string i_MediaFile,Size i_Size,int i_Stream)
{
this.MediaDecteor.Filename = i_MediaFile;
this.MediaDecteor.CurrentStream = 0;
//int m_ImageSize = (int)this.MediaDecteor.StreamLength;
try
{
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);
byte[] m_bytes = new byte[m_stream.Length];
m_stream.Read(m_bytes,0,m_bytes.Length);
m_stream.Close();
File.Delete("Temp.bmp");
MemoryStream m_MemoStream = new MemoryStream(m_bytes.Length);
m_MemoStream.Write(m_bytes,0,m_bytes.Length);
return Image.FromStream(m_MemoStream);
}
catch(Exception ex)
{
this.FileErrorEvent(ex);
return null;
}
}
private bool ThumbnailCallback()
{
return false;
}
//ctor
public MediaDetector()
{
}
}
public class MediaHelper#region public class MediaHelper
public class MediaHelper
{
static public MediaTypes ConvertToMediaType(int i_Type)
{
switch(i_Type)
{
default:
case 0:
return MediaTypes.Unknow;
case 1:
return MediaTypes.Image;
case 2:
return MediaTypes.Video;
case 3:
return MediaTypes.Audio;
}
}
static public MediaTypes ConvertToMediaType(string i_Type)
{
switch(i_Type.ToLower())
{
default:
case "unknow":
return MediaTypes.Unknow;
case "image":
return MediaTypes.Image;
case "video":
return MediaTypes.Video;
case "audio":
return MediaTypes.Audio;
}
}
}
#endregion
public delegate void ErrorHandler(object i_Sender,Exception i_ex);
public enum MediaTypes
{
Image = 1,
Video = 2,
Audio = 3,
Unknow = 0,
}
}
using System;
using System.IO;
using DexterLib;
using System.Drawing;
using System.Drawing.Imaging;
namespace PublicLibrary
{
/**//// <summary>
/// Summary description for MediaDetector.
/// </summary>
public class MediaDetector
{
//fields
protected MediaDetClass _MediaDet;
protected Image.GetThumbnailImageAbort _ImageCallback;
//events
public event ErrorHandler OnError;
//properties
protected MediaDetClass MediaDecteor
{
get
{
if(this._MediaDet==null)
{
try
{
this._MediaDet = new MediaDetClass();
}
catch(Exception ex)
{
this.FileErrorEvent(ex);
}
}
return _MediaDet;
}
}
protected Image.GetThumbnailImageAbort ImageCallback
{
get
{
if(this._ImageCallback == null)
{
this._ImageCallback = new Image.GetThumbnailImageAbort(ThumbnailCallback);
}
return this._ImageCallback;
}
}
//methods
private void FileErrorEvent(Exception i_ex)
{
if(this.OnError!=null)
{
try
{
this.OnError(this,i_ex);
}
catch(Exception ex)
{
System.Diagnostics.Trace.WriteLine(ex.Message);
}
}
}
/**//// <summary>
/// Method to get thumbinal image from media file.
/// </summary>
/// <param name="i_MediaFile">Media file full path and name.</param>
/// <param name="i_Size">Image size.</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>
/// <returns></returns>
public Image GetThumbnail(string i_MediaFile,Size i_Size,MediaTypes i_type,int i_Stream)
{
switch(i_type)
{
default:
case MediaTypes.Unknow:
this.FileErrorEvent(new Exception("Unknow media type."));
return null;
case MediaTypes.Audio:
this.FileErrorEvent(new Exception("This media type has not implemented to create an image."));
return null;
case MediaTypes.Image:
return this.GetThumbnailFromImage(i_MediaFile,i_Size);
case MediaTypes.Video:
return this.GetThumbnailFromVideo(i_MediaFile,i_Size,i_Stream);
}
}
public Image GetThumbnailFromImage(string i_MediaFile,Size i_Size)
{
try
{
Image m_image = Image.FromFile(i_MediaFile);
return m_image.GetThumbnailImage(i_Size.Width,i_Size.Height,this.ImageCallback,IntPtr.Zero);
}
catch(Exception ex)
{
this.FileErrorEvent(ex);
return null;
}
}
public Image GetThumbnailFromVideo(string i_MediaFile,Size i_Size,int i_Stream)
{
this.MediaDecteor.Filename = i_MediaFile;
this.MediaDecteor.CurrentStream = 0;
//int m_ImageSize = (int)this.MediaDecteor.StreamLength;
try
{
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);
byte[] m_bytes = new byte[m_stream.Length];
m_stream.Read(m_bytes,0,m_bytes.Length);
m_stream.Close();
File.Delete("Temp.bmp");
MemoryStream m_MemoStream = new MemoryStream(m_bytes.Length);
m_MemoStream.Write(m_bytes,0,m_bytes.Length);
return Image.FromStream(m_MemoStream);
}
catch(Exception ex)
{
this.FileErrorEvent(ex);
return null;
}
}
private bool ThumbnailCallback()
{
return false;
}
//ctor
public MediaDetector()
{
}
}
public class MediaHelper#region public class MediaHelper
public class MediaHelper
{
static public MediaTypes ConvertToMediaType(int i_Type)
{
switch(i_Type)
{
default:
case 0:
return MediaTypes.Unknow;
case 1:
return MediaTypes.Image;
case 2:
return MediaTypes.Video;
case 3:
return MediaTypes.Audio;
}
}
static public MediaTypes ConvertToMediaType(string i_Type)
{
switch(i_Type.ToLower())
{
default:
case "unknow":
return MediaTypes.Unknow;
case "image":
return MediaTypes.Image;
case "video":
return MediaTypes.Video;
case "audio":
return MediaTypes.Audio;
}
}
}
#endregion
public delegate void ErrorHandler(object i_Sender,Exception i_ex);
public enum MediaTypes
{
Image = 1,
Video = 2,
Audio = 3,
Unknow = 0,
}
}
测试Form代码:
Form类
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
//
using PublicLibrary;
namespace Country.Study
{
/**//// <summary>
/// Summary description for Thumbinal.
/// </summary>
public class Thumbnail : System.Windows.Forms.Form
{
private MediaDetector _MediaDetector;
//
private MediaDetector MediaDetector
{
get
{
return this._MediaDetector;
}
}
//
private System.Windows.Forms.StatusBar statusBar1;
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.TextBox C_Path;
private System.Windows.Forms.Button C_Browse;
private System.Windows.Forms.Panel panel2;
private System.Windows.Forms.Label C_LabWidth;
private System.Windows.Forms.TextBox C_Width;
private System.Windows.Forms.Label C_LabHeight;
private System.Windows.Forms.TextBox C_Height;
private System.Windows.Forms.Label C_LabType;
private System.Windows.Forms.ComboBox C_MediaTypes;
private System.Windows.Forms.Label C_LabStream;
private System.Windows.Forms.Button C_Create;
private System.Windows.Forms.OpenFileDialog C_OpenFileDialog;
private System.Windows.Forms.TextBox C_Stream;
private System.Windows.Forms.PictureBox C_PicBox;
/**//// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public Thumbnail()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
this._MediaDetector = new MediaDetector();
this._MediaDetector.OnError += new ErrorHandler(MediaDetector_OnError);
}
/**//// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if(this._MediaDetector!=null)
{
this._MediaDetector.OnError -= new ErrorHandler(MediaDetector_OnError);
this._MediaDetector = null;
}
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
Windows Form Designer generated code#region Windows Form Designer generated code
/**//// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.statusBar1 = new System.Windows.Forms.StatusBar();
this.panel1 = new System.Windows.Forms.Panel();
this.C_Browse = new System.Windows.Forms.Button();
this.C_Path = new System.Windows.Forms.TextBox();
this.panel2 = new System.Windows.Forms.Panel();
this.C_Create = new System.Windows.Forms.Button();
this.C_Stream = new System.Windows.Forms.TextBox();
this.C_LabStream = new System.Windows.Forms.Label();
this.C_MediaTypes = new System.Windows.Forms.ComboBox();
this.C_LabType = new System.Windows.Forms.Label();
this.C_Height = new System.Windows.Forms.TextBox();
this.C_LabHeight = new System.Windows.Forms.Label();
this.C_LabWidth = new System.Windows.Forms.Label();
this.C_Width = new System.Windows.Forms.TextBox();
this.C_PicBox = new System.Windows.Forms.PictureBox();
this.C_OpenFileDialog = new System.Windows.Forms.OpenFileDialog();
this.panel1.SuspendLayout();
this.panel2.SuspendLayout();
this.SuspendLayout();
//
// statusBar1
//
this.statusBar1.Location = new System.Drawing.Point(0, 391);
this.statusBar1.Name = "statusBar1";
this.statusBar1.Size = new System.Drawing.Size(568, 22);
this.statusBar1.TabIndex = 0;
this.statusBar1.Text = "statusBar1";
//
// panel1
//
this.panel1.Controls.Add(this.C_Browse);
this.panel1.Controls.Add(this.C_Path);
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(568, 40);
this.panel1.TabIndex = 1;
//
// C_Browse
//
this.C_Browse.Location = new System.Drawing.Point(480, 8);
this.C_Browse.Name = "C_Browse";
this.C_Browse.TabIndex = 1;
this.C_Browse.Text = "Browse";
this.C_Browse.Click += new System.EventHandler(this.C_Browse_Click);
//
// C_Path
//
this.C_Path.Location = new System.Drawing.Point(8, 8);
this.C_Path.Name = "C_Path";
this.C_Path.ReadOnly = true;
this.C_Path.Size = new System.Drawing.Size(464, 20);
this.C_Path.TabIndex = 0;
this.C_Path.Text = "textBox1";
//
// panel2
//
this.panel2.Controls.Add(this.C_Create);
this.panel2.Controls.Add(this.C_Stream);
this.panel2.Controls.Add(this.C_LabStream);
this.panel2.Controls.Add(this.C_MediaTypes);
this.panel2.Controls.Add(this.C_LabType);
this.panel2.Controls.Add(this.C_Height);
this.panel2.Controls.Add(this.C_LabHeight);
this.panel2.Controls.Add(this.C_LabWidth);
this.panel2.Controls.Add(this.C_Width);
this.panel2.Dock = System.Windows.Forms.DockStyle.Left;
this.panel2.Location = new System.Drawing.Point(0, 40);
this.panel2.Name = "panel2";
this.panel2.Size = new System.Drawing.Size(176, 351);
this.panel2.TabIndex = 2;
//
// C_Create
//
this.C_Create.Location = new System.Drawing.Point(8, 136);
this.C_Create.Name = "C_Create";
this.C_Create.Size = new System.Drawing.Size(152, 23);
this.C_Create.TabIndex = 10;
this.C_Create.Text = "Create Thumbnail Image";
this.C_Create.Click += new System.EventHandler(this.C_Create_Click);
//
// C_Stream
//
this.C_Stream.Location = new System.Drawing.Point(64, 104);
this.C_Stream.Name = "C_Stream";
this.C_Stream.TabIndex = 9;
this.C_Stream.Text = "1";
//
// C_LabStream
//
this.C_LabStream.Location = new System.Drawing.Point(8, 104);
this.C_LabStream.Name = "C_LabStream";
this.C_LabStream.Size = new System.Drawing.Size(56, 16);
this.C_LabStream.TabIndex = 8;
this.C_LabStream.Text = "Stream";
//
// C_MediaTypes
//
this.C_MediaTypes.Items.AddRange(new object[] {
"Unknow",
"Image",
"Audio",
"Video"});
this.C_MediaTypes.Location = new System.Drawing.Point(64, 72);
this.C_MediaTypes.Name = "C_MediaTypes";
this.C_MediaTypes.Size = new System.Drawing.Size(104, 21);
this.C_MediaTypes.TabIndex = 7;
//
// C_LabType
//
this.C_LabType.Location = new System.Drawing.Point(8, 72);
this.C_LabType.Name = "C_LabType";
this.C_LabType.Size = new System.Drawing.Size(56, 16);
this.C_LabType.TabIndex = 6;
this.C_LabType.Text = "Type";
//
// C_Height
//
this.C_Height.Location = new System.Drawing.Point(64, 40);
this.C_Height.Name = "C_Height";
this.C_Height.TabIndex = 5;
this.C_Height.Text = "300";
//
// C_LabHeight
//
this.C_LabHeight.Location = new System.Drawing.Point(8, 40);
this.C_LabHeight.Name = "C_LabHeight";
this.C_LabHeight.Size = new System.Drawing.Size(56, 16);
this.C_LabHeight.TabIndex = 4;
this.C_LabHeight.Text = "Height";
//
// C_LabWidth
//
this.C_LabWidth.Location = new System.Drawing.Point(8, 8);
this.C_LabWidth.Name = "C_LabWidth";
this.C_LabWidth.Size = new System.Drawing.Size(56, 16);
this.C_LabWidth.TabIndex = 3;
this.C_LabWidth.Text = "Width";
//
// C_Width
//
this.C_Width.Location = new System.Drawing.Point(64, 8);
this.C_Width.Name = "C_Width";
this.C_Width.TabIndex = 3;
this.C_Width.Text = "300";
//
// C_PicBox
//
this.C_PicBox.Location = new System.Drawing.Point(176, 40);
this.C_PicBox.Name = "C_PicBox";
this.C_PicBox.Size = new System.Drawing.Size(392, 351);
this.C_PicBox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
this.C_PicBox.TabIndex = 3;
this.C_PicBox.TabStop = false;
//
// Thumbnail
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(568, 413);
this.Controls.Add(this.C_PicBox);
this.Controls.Add(this.panel2);
this.Controls.Add(this.panel1);
this.Controls.Add(this.statusBar1);
this.Name = "Thumbnail";
this.Text = "Thumbinal";
this.panel1.ResumeLayout(false);
this.panel2.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private void C_Create_Click(object sender, System.EventArgs e)
{
try
{
int m_width = Convert.ToInt32(this.C_Width.Text);
int m_height = Convert.ToInt32(this.C_Height.Text);
int m_stream = Convert.ToInt32(this.C_Stream.Text);
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);
this.C_PicBox.Image = m_image;
this.C_PicBox.Width = m_width;
this.C_PicBox.Height = m_height;
this.C_PicBox.Refresh();
}
catch(Exception ex)
{
MessageBox.Show(string.Format("Error:{0}",ex.Message));
}
}
private void MediaDetector_OnError(object i_Sender, Exception i_ex)
{
MessageBox.Show(this,string.Format("Create thumbnail image error. Message:{0}",i_ex.Message));
}
private void C_Browse_Click(object sender, System.EventArgs e)
{
if(this.C_OpenFileDialog.ShowDialog(this)==DialogResult.OK)
{
this.C_Path.Text = this.C_OpenFileDialog.FileName;
}
}
}
}
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
//
using PublicLibrary;
namespace Country.Study
{
/**//// <summary>
/// Summary description for Thumbinal.
/// </summary>
public class Thumbnail : System.Windows.Forms.Form
{
private MediaDetector _MediaDetector;
//
private MediaDetector MediaDetector
{
get
{
return this._MediaDetector;
}
}
//
private System.Windows.Forms.StatusBar statusBar1;
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.TextBox C_Path;
private System.Windows.Forms.Button C_Browse;
private System.Windows.Forms.Panel panel2;
private System.Windows.Forms.Label C_LabWidth;
private System.Windows.Forms.TextBox C_Width;
private System.Windows.Forms.Label C_LabHeight;
private System.Windows.Forms.TextBox C_Height;
private System.Windows.Forms.Label C_LabType;
private System.Windows.Forms.ComboBox C_MediaTypes;
private System.Windows.Forms.Label C_LabStream;
private System.Windows.Forms.Button C_Create;
private System.Windows.Forms.OpenFileDialog C_OpenFileDialog;
private System.Windows.Forms.TextBox C_Stream;
private System.Windows.Forms.PictureBox C_PicBox;
/**//// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public Thumbnail()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
this._MediaDetector = new MediaDetector();
this._MediaDetector.OnError += new ErrorHandler(MediaDetector_OnError);
}
/**//// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if(this._MediaDetector!=null)
{
this._MediaDetector.OnError -= new ErrorHandler(MediaDetector_OnError);
this._MediaDetector = null;
}
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
Windows Form Designer generated code#region Windows Form Designer generated code
/**//// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.statusBar1 = new System.Windows.Forms.StatusBar();
this.panel1 = new System.Windows.Forms.Panel();
this.C_Browse = new System.Windows.Forms.Button();
this.C_Path = new System.Windows.Forms.TextBox();
this.panel2 = new System.Windows.Forms.Panel();
this.C_Create = new System.Windows.Forms.Button();
this.C_Stream = new System.Windows.Forms.TextBox();
this.C_LabStream = new System.Windows.Forms.Label();
this.C_MediaTypes = new System.Windows.Forms.ComboBox();
this.C_LabType = new System.Windows.Forms.Label();
this.C_Height = new System.Windows.Forms.TextBox();
this.C_LabHeight = new System.Windows.Forms.Label();
this.C_LabWidth = new System.Windows.Forms.Label();
this.C_Width = new System.Windows.Forms.TextBox();
this.C_PicBox = new System.Windows.Forms.PictureBox();
this.C_OpenFileDialog = new System.Windows.Forms.OpenFileDialog();
this.panel1.SuspendLayout();
this.panel2.SuspendLayout();
this.SuspendLayout();
//
// statusBar1
//
this.statusBar1.Location = new System.Drawing.Point(0, 391);
this.statusBar1.Name = "statusBar1";
this.statusBar1.Size = new System.Drawing.Size(568, 22);
this.statusBar1.TabIndex = 0;
this.statusBar1.Text = "statusBar1";
//
// panel1
//
this.panel1.Controls.Add(this.C_Browse);
this.panel1.Controls.Add(this.C_Path);
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(568, 40);
this.panel1.TabIndex = 1;
//
// C_Browse
//
this.C_Browse.Location = new System.Drawing.Point(480, 8);
this.C_Browse.Name = "C_Browse";
this.C_Browse.TabIndex = 1;
this.C_Browse.Text = "Browse";
this.C_Browse.Click += new System.EventHandler(this.C_Browse_Click);
//
// C_Path
//
this.C_Path.Location = new System.Drawing.Point(8, 8);
this.C_Path.Name = "C_Path";
this.C_Path.ReadOnly = true;
this.C_Path.Size = new System.Drawing.Size(464, 20);
this.C_Path.TabIndex = 0;
this.C_Path.Text = "textBox1";
//
// panel2
//
this.panel2.Controls.Add(this.C_Create);
this.panel2.Controls.Add(this.C_Stream);
this.panel2.Controls.Add(this.C_LabStream);
this.panel2.Controls.Add(this.C_MediaTypes);
this.panel2.Controls.Add(this.C_LabType);
this.panel2.Controls.Add(this.C_Height);
this.panel2.Controls.Add(this.C_LabHeight);
this.panel2.Controls.Add(this.C_LabWidth);
this.panel2.Controls.Add(this.C_Width);
this.panel2.Dock = System.Windows.Forms.DockStyle.Left;
this.panel2.Location = new System.Drawing.Point(0, 40);
this.panel2.Name = "panel2";
this.panel2.Size = new System.Drawing.Size(176, 351);
this.panel2.TabIndex = 2;
//
// C_Create
//
this.C_Create.Location = new System.Drawing.Point(8, 136);
this.C_Create.Name = "C_Create";
this.C_Create.Size = new System.Drawing.Size(152, 23);
this.C_Create.TabIndex = 10;
this.C_Create.Text = "Create Thumbnail Image";
this.C_Create.Click += new System.EventHandler(this.C_Create_Click);
//
// C_Stream
//
this.C_Stream.Location = new System.Drawing.Point(64, 104);
this.C_Stream.Name = "C_Stream";
this.C_Stream.TabIndex = 9;
this.C_Stream.Text = "1";
//
// C_LabStream
//
this.C_LabStream.Location = new System.Drawing.Point(8, 104);
this.C_LabStream.Name = "C_LabStream";
this.C_LabStream.Size = new System.Drawing.Size(56, 16);
this.C_LabStream.TabIndex = 8;
this.C_LabStream.Text = "Stream";
//
// C_MediaTypes
//
this.C_MediaTypes.Items.AddRange(new object[] {
"Unknow",
"Image",
"Audio",
"Video"});
this.C_MediaTypes.Location = new System.Drawing.Point(64, 72);
this.C_MediaTypes.Name = "C_MediaTypes";
this.C_MediaTypes.Size = new System.Drawing.Size(104, 21);
this.C_MediaTypes.TabIndex = 7;
//
// C_LabType
//
this.C_LabType.Location = new System.Drawing.Point(8, 72);
this.C_LabType.Name = "C_LabType";
this.C_LabType.Size = new System.Drawing.Size(56, 16);
this.C_LabType.TabIndex = 6;
this.C_LabType.Text = "Type";
//
// C_Height
//
this.C_Height.Location = new System.Drawing.Point(64, 40);
this.C_Height.Name = "C_Height";
this.C_Height.TabIndex = 5;
this.C_Height.Text = "300";
//
// C_LabHeight
//
this.C_LabHeight.Location = new System.Drawing.Point(8, 40);
this.C_LabHeight.Name = "C_LabHeight";
this.C_LabHeight.Size = new System.Drawing.Size(56, 16);
this.C_LabHeight.TabIndex = 4;
this.C_LabHeight.Text = "Height";
//
// C_LabWidth
//
this.C_LabWidth.Location = new System.Drawing.Point(8, 8);
this.C_LabWidth.Name = "C_LabWidth";
this.C_LabWidth.Size = new System.Drawing.Size(56, 16);
this.C_LabWidth.TabIndex = 3;
this.C_LabWidth.Text = "Width";
//
// C_Width
//
this.C_Width.Location = new System.Drawing.Point(64, 8);
this.C_Width.Name = "C_Width";
this.C_Width.TabIndex = 3;
this.C_Width.Text = "300";
//
// C_PicBox
//
this.C_PicBox.Location = new System.Drawing.Point(176, 40);
this.C_PicBox.Name = "C_PicBox";
this.C_PicBox.Size = new System.Drawing.Size(392, 351);
this.C_PicBox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
this.C_PicBox.TabIndex = 3;
this.C_PicBox.TabStop = false;
//
// Thumbnail
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(568, 413);
this.Controls.Add(this.C_PicBox);
this.Controls.Add(this.panel2);
this.Controls.Add(this.panel1);
this.Controls.Add(this.statusBar1);
this.Name = "Thumbnail";
this.Text = "Thumbinal";
this.panel1.ResumeLayout(false);
this.panel2.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private void C_Create_Click(object sender, System.EventArgs e)
{
try
{
int m_width = Convert.ToInt32(this.C_Width.Text);
int m_height = Convert.ToInt32(this.C_Height.Text);
int m_stream = Convert.ToInt32(this.C_Stream.Text);
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);
this.C_PicBox.Image = m_image;
this.C_PicBox.Width = m_width;
this.C_PicBox.Height = m_height;
this.C_PicBox.Refresh();
}
catch(Exception ex)
{
MessageBox.Show(string.Format("Error:{0}",ex.Message));
}
}
private void MediaDetector_OnError(object i_Sender, Exception i_ex)
{
MessageBox.Show(this,string.Format("Create thumbnail image error. Message:{0}",i_ex.Message));
}
private void C_Browse_Click(object sender, System.EventArgs e)
{
if(this.C_OpenFileDialog.ShowDialog(this)==DialogResult.OK)
{
this.C_Path.Text = this.C_OpenFileDialog.FileName;
}
}
}
}
仅做参考!