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

📄 drawdib.cs

📁 实现微软OFFICEACCESE数据库自动备份功能
💻 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 PictureBox Control;
		public BITMAPINFOHEADER BITMAPINFOHEADER;
        
		public IntPtr Handle
		{
			get{return this.hdd;}
		}
		public DrawDib(int width,int height)
		{
            if (width <= 0 || height <= 0)
            {
                width = 176;
                height = 144;
            }
            this.SrcRect = this.DstRect = new Rectangle(0, 0, width, height);
             
		}
		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);
            //MessageBox.Show(this.SrcRect.Width.ToString() + " " + this.SrcRect.Height.ToString());

		}
        /*
        public void Open(int v_Width, int v_Height)
        {

            this.hdd = DrawDibOpen();
            Debug.Assert(hdd != IntPtr.Zero);
            bool b = DrawDibBegin(hdd, IntPtr.Zero, v_Width, v_Height, ref this.BITMAPINFOHEADER, this.SrcRect.Width, this.SrcRect.Height, 0);

        }
         * */
		public void Draw(byte[] data)
		{
			using(Graphics g = this.Control.CreateGraphics())
			{
		 		//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,
					176,
					144,
					ref this.BITMAPINFOHEADER,
					data,
					this.SrcRect.X,
					this.SrcRect.Y,this.SrcRect.Width,this.SrcRect.Height,0 );

                //outbmp = Graphics.FromHdc(hdc);
                //outbmp.CopyFromScreen(SrcRect.X, SrcRect.Y, DstRect.X, DstRect.Y, new Size(176, 144));
				g.ReleaseHdc(hdc);
                 
                
                 
			}

            

		}
        /*
        public void Draw(byte[] data,int v_Width,int v_Height)
        {
            using (Graphics g = this.Control.CreateGraphics())
            {
                //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,
                    v_Width,
                    v_Height,
                    ref this.BITMAPINFOHEADER,
                    data,
                    this.SrcRect.X,
                    this.SrcRect.Y, this.SrcRect.Width, this.SrcRect.Height, 0);
                //MessageBox.Show(this.SrcRect.Width.ToString() + " " + this.SrcRect.Height.ToString());


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