扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
作者:中国IT实验室 来源:中国IT实验室 2007年10月2日
关键字:

using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.Drawing;
namespace MovieGrabberCSharp
...{
class MovieGrabberDLL
...{
[DllImport("MovieGrabberDLL.dll")]
public static extern int fnMovieGrabberDLL();
[DllImport("MovieGrabberDLL.dll")]
public static extern IntPtr GrabMovieFrame(string aPath, int grayColorCountThreshold);
public static Bitmap GrabMovieFrameBitmap(string aPath,int grayColorCountThreshold)
...{
IntPtr hBitmap = GrabMovieFrame(aPath, grayColorCountThreshold);
if(hBitmap == IntPtr.Zero)
return null;
return Bitmap.FromHbitmap(hBitmap);
}
public static Bitmap GrabMovieFrameBitmap(string aPath)
...{
return GrabMovieFrameBitmap(aPath, 8);
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace MovieGrabberCSharp
...{
public partial class MainForm : Form
...{
public MainForm()
...{
InitializeComponent();
}
private void OpenMovieFilePathButton_Click(object sender, EventArgs e)
...{
OpenFileDialog dlg = new OpenFileDialog();
if (dlg.ShowDialog() == DialogResult.OK)
...{
MovieFilePathTextBox.Text = dlg.FileName;
}
}
private void GrabberButton_Click(object sender, EventArgs e)
...{
Bitmap bitmap = MovieGrabberDLL.GrabMovieFrameBitmap(MovieFilePathTextBox.Text);
if (bitmap != null)
...{
MessageBox.Show("抓图成功!");
GrabberPictureBox.SizeMode = PictureBoxSizeMode.StretchImage;
GrabberPictureBox.Image = bitmap;
GrabberPictureBox.Invalidate();
GrabberPictureBox.Refresh();
}
else
...{
MessageBox.Show("失败!");
}
}
private void ExitButton_Click(object sender, EventArgs e)
...{
this.Close();
}
}
}


如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。