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

📄 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 LanMsg.AV
{
	/// <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);
			bool b=DrawDibBegin(hdd,IntPtr.Zero,this.DstRect.Width,this.DstRect.Height,ref this.BITMAPINFOHEADER,this.SrcRect.Width,this.SrcRect.Height,0);

		}

		public void Draw(byte[] data,int width,int height)
		{
			using(Graphics g=this.Control.CreateGraphics())
			{
				IntPtr hdc=g.GetHdc();
				bool b=DrawDibDraw(
					hdd,
					hdc,
					this.DstRect.X,
					this.DstRect.Y,
					width,
					height,
					ref this.BITMAPINFOHEADER,
					data,
					this.SrcRect.X,
					this.SrcRect.Y,width,height,0);

				g.ReleaseHdc(hdc);
			}
		}

		public void Draw(byte[] data)
		{
			using(Graphics g=this.Control.CreateGraphics())
			{
				IntPtr hdc=g.GetHdc();
				bool b=DrawDibDraw(
					hdd,
					hdc,
					this.DstRect.X,
					this.DstRect.Y,
					this.DstRect.Width,
					this.DstRect.Height,
					ref this.BITMAPINFOHEADER,
					data,
					this.SrcRect.X,
					this.SrcRect.Y,this.SrcRect.Width,this.SrcRect.Height,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();

		/*
		**  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 + -