⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ~drawdib.cs

📁 语音视频功能 里面实现了基本的QQ与语音对话
💻 CS
字号:
using System;
using System.Text;
using System.Drawing;
using System.Diagnostics;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace gowk.multimedia
{
	/// <summary>
	/// DrawDib 的摘要说明。
	/// </summary>
	public class DrawDib 
	{
		public Rectangle SrcRect,DstRect;
		IntPtr hdd;
		public Control Control;
		public BITMAPINFOHEADER BITMAPINFOHEADER;
		public IntPtr Handle
		{
			get{return this.hdd;}
		}
		public DrawDib()
		{
			this.SrcRect=this.DstRect=new Rectangle(0,0,160,120);
		}
		public void Open()
		{
			this.hdd=DrawDibOpen();
			Debug.Assert(hdd!=IntPtr.Zero);
			
			bmi=new BITMAPINFOHEADER();

			bmi.biCompression =(int) BI.BI_RGB;
			bmi.biWidth = 80;
			bmi.biHeight = 60;
			bmi.biPlanes = 1;
			bmi.biBitCount = 24;
			bmi.biXPelsPerMeter = 0;
			bmi.biYPelsPerMeter = 0;
			bmi.biClrUsed = 0;
			bmi.biClrImportant = 0;
			bmi.biSizeImage=80*60*3;
			bmi.biSize=Marshal.SizeOf(bmi);

			bool b=DrawDibBegin(hdd,IntPtr.Zero,160,120,ref bmi,160,120,0);

		}
		
		BITMAPINFOHEADER bmi;
		public void Draw(byte[] data)
		{
			using(Graphics g=this.Control.CreateGraphics())
			{
				byte[] data2=new byte[this.bmi.biSizeImage];
				StretchDIB(ref bmi,data2,0,0,80,60,ref this.BITMAPINFOHEADER,data,0,0,80,60);
				byte[] data3=new byte[this.BITMAPINFOHEADER.biSizeImage];
				StretchDIB(ref BITMAPINFOHEADER,data3,0,0,160,120,ref this.bmi,data2,0,0,160,120);
		//		g.DrawRectangle(new Pen(Color.Red,2),this.Control.ClientRectangle);
				IntPtr hdc=g.GetHdc();
				bool b=DrawDibDraw(
					hdd,
					hdc,
					this.DstRect.X,
					this.DstRect.Y,
					160,
					120,
					ref this.BITMAPINFOHEADER,
					data3,
					this.SrcRect.X,
					this.SrcRect.Y,160,120,0 );

				g.ReleaseHdc(hdc);
			}
		}
		public void Close()
		{
			if(hdd!=IntPtr.Zero)
			{
				DrawDibEnd(hdd);
				DrawDibClose(hdd);
			}
		}
		public bool IsOpened
		{
			get{return this.hdd!=IntPtr.Zero;}
		}
		#region
		/*
		**  DrawDibOpen()
		**
		*/
		[DllImport("MSVFW32.dll")]
		public static extern IntPtr DrawDibOpen();

		[DllImport("MSVFW32.dll")]
		public static extern void StretchDIB(
						ref BITMAPINFOHEADER biDst,
						byte[]	lpDst,		
						int	DstX,		
						int	DstY,		
						int	DstXE,		
						int	DstYE,		
						ref BITMAPINFOHEADER biSrc,
						byte[] lpSrc,		
						int	SrcX,		
						int	SrcY,		
						int	SrcXE,		
						int	SrcYE); 

		[DllImport("GDI32.dll")]
		public static extern bool StretchBlt(
			IntPtr hdcDest,      // handle to destination DC
			int nXOriginDest, // x-coord of destination upper-left corner
			int nYOriginDest, // y-coord of destination upper-left corner
			int nWidthDest,   // width of destination rectangle
			int nHeightDest,  // height of destination rectangle
			IntPtr hdcSrc,       // handle to source DC
			int nXOriginSrc,  // x-coord of source upper-left corner
			int nYOriginSrc,  // y-coord of source upper-left corner
			int nWidthSrc,    // width of source rectangle
			int nHeightSrc,   // height of source rectangle
			int dwRop       // raster operation code
			);
		/*
		**  DrawDibClose()
		**
		*/
		[DllImport("MSVFW32.dll")]
		public static extern bool DrawDibClose(IntPtr hdd);
		
		[DllImport("MSVFW32.dll")]
		public static extern bool DrawDibBegin(
			IntPtr hdd,
			IntPtr      hdc,
			int      dxDst,
			int      dyDst,
			ref BITMAPINFOHEADER lpbi,
			int      dxSrc,
			int      dySrc,
			int     wFlags
			);
		[DllImport("MSVFW32.dll")]
		public static extern bool DrawDibEnd(IntPtr hdd);
		/*
		**  DrawDibDraw()
		**
		**  actualy draw a DIB to the screen.
		**
		*/
		[DllImport("MSVFW32.dll")]
		public static extern bool DrawDibDraw(
			IntPtr hdd,
			IntPtr      hdc,
			int      xDst,
			int      yDst,
			int      dxDst,
			int      dyDst,
			ref BITMAPINFOHEADER lpbi,
			byte[]   lpBits,
			int      xSrc,
			int      ySrc,
			int      dxSrc,
			int      dySrc,
			uint     wFlags
			);
		#endregion
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -