扫一扫
分享文章到微信

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

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

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