用C#的PictureBox播放本地视频

来源:互联网 发布:淘宝买家秀搞笑带评价 编辑:程序博客网 时间:2024/05/26 14:10
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using System.Collections;using System.Runtime.InteropServices;namespace WindowsFormsApplication1{    //API函数声明       public partial class Form1 : Form    {        public Form1()        {            InitializeComponent();        }        private void button1_Click(object sender, EventArgs e)        {                        PictureBox PlayScreen = pictureBox1;            string mciCommand;            //打开指定位置的视频文件            mciCommand = "open " + " D:\\picture\\2.wmv " + " alias MyAVI ";            mciCommand = mciCommand + " parent " + PlayScreen.Handle.ToInt32() + " style child ";            LibWrap.mciSendString(mciCommand, null, 0, 0);            Rectangle r = PlayScreen.ClientRectangle;            mciCommand = " put MyAVI window at 0 0 " + r.Width + " " + r.Height;            LibWrap.mciSendString(mciCommand, null, 0, 0);            LibWrap.mciSendString(" play MyAVI ", null, 0, 0);        }        public class LibWrap        {            //mciSendString为API函数,使用C#调用API函数在pictureBox上显示视频            [DllImport(("winmm.dll "), EntryPoint = "mciSendString", CharSet = CharSet.Auto)]            public static extern int mciSendString(string lpszCommand, string lpszReturnString,                        uint cchReturn, int hwndCallback);        }        //界面退出按钮        private void button2_Click(object sender, EventArgs e)        {            DialogResult r = MessageBox.Show("退出系统", "提示", MessageBoxButtons.OKCancel,MessageBoxIcon.Information);            Application.Exit();        }        private void button3_Click(object sender, EventArgs e)        {            Bitmap bit = new Bitmap(this.Width, this.Height);//实例化一个和窗体一样大的bitmap            Graphics g = Graphics.FromImage(bit);            g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;//图像质量设为最好            //g.CopyFromScreen( this.Left,this.Top,0,0,new Size(this.Width,this.Height));//对整个窗体屏幕截图            //g.CopyFromScreen( axWindowsMediaPlayer1.PointToScreen(Point.Empty), Point.Empty, axWindowsMediaPlayer1.Size);//对windowsmediaplayer截图            g.CopyFromScreen(pictureBox1.PointToScreen(Point.Empty), Point.Empty, pictureBox1.Size);            bit.Save("D:\\" + DateTime.Now.ToString("HHmmss") + ".jpg");//保存图片        }    }   }

1 0
原创粉丝点击