• 大小: 39KB
    文件类型: .rar
    金币: 2
    下载: 1 次
    发布日期: 2021-05-26
  • 语言: C#
  • 标签: c#  双缓冲  GDI+  BitBlt  

资源简介

利用GDI+在Form中绘制60*60个圆点,显示帧速,使用三种不同方法,分别是: 1.直接绘制 2.使用双缓冲 3.使用BitBlt函数 对比三种函数的帧速,以及提速效果 开发环境为vs2008

资源截图

代码片段和文件信息

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.Drawing.Imaging;
using System.Runtime.InteropServices;
 
namespace BitBltTest
{
    //[System.Runtime.InteropServices.DllImport(“gdi32.dll“)]
    //private static extern int BitBlt(
    //    IntPtr hdcDest
    //    int nXDest
    //    int nYDest
    //    int nWidth
    //    int nHeight
    //    IntPtr hdcSrc 
    //    int nXSrc
    //    int nYSrc
    //    System.Int32 dwRop  // raster operation code
    //  );

    public partial class Form1 : Form
    {
        Bitmap bitmap;
        bool flag;
        SolidBrush brushbrush1 brush2;
        Graphics ClientDC memDC offScreenDC;
        IntPtr hdc memdc;
        //声明一个API函数 
        [System.Runtime.InteropServices.DllImportAttribute(“gdi32.dll“)]

        private static extern bool BitBlt(
            IntPtr hdcDest // 目标 DC的句柄 
            int nXDest
            int nYDest
            int nWidth
            int nHeight
            IntPtr hdcSrc // 源DC的句柄 
            int nXSrc
            int nYSrc
            System.Int32 dwRop // 光栅的处理数值 
        );
        [DllImport(“gdi32.dll“ EntryPoint = “CreateCompatibleDC“)]
        public static extern IntPtr CreateCompatibleDC(IntPtr hdc);

        [DllImport(“gdi32.dll“ EntryPoint = “Selectobject“)]
        public static extern IntPtr Selectobject(IntPtr hdc IntPtr hbitmap);

        [DllImport(“gdi32.dll“ EntryPoint = “DeleteDC“)]
        public static extern IntPtr DeleteDC(IntPtr hDc);

        [DllImport(“gdi32.dll“ EntryPoint = “Deleteobject“)]
        public static extern IntPtr Deleteobject(IntPtr bmp);
 
        public Form1()
        {
            InitializeComponent();
            bitmap = new Bitmap(600 600);
            brush1 = new SolidBrush(Color.Red);
            brush2 = new SolidBrush(Color.Blue);
        }

        private void timer1_Tick(object sender EventArgs e)
        {
            DateTime t = DateTime.Now;
            ClientDC = this.CreateGraphics();
            memDC = Graphics.FromImage(bitmap);
            if (flag)
            {
                brush = brush1;
                flag = false;
            }
            else
            {
                brush = brush2;
                flag = true;
            }
            for (int j = 0; j < 60; j++)
            {
                for (int i = 0; i < 60; i++)
                {
                    ClientDC.FillEllipse(brush i * 10 j * 10 10 10);
                }
            }
            DateTime t2 = DateTime.Now;
            TimeSpan sp = t2 - t;
            float per = 1000 / sp.Milliseconds;
            this.label1.Text = “速度“ + per.ToString() + “帧/秒“;
        }

        private void button1_Click(object sender EventArgs e)
        {
      

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件      11264  2013-07-02 21:26  BitBltTest\BitBltTest\bin\Debug\BitBltTest.exe

     文件      26112  2013-07-02 21:26  BitBltTest\BitBltTest\bin\Debug\BitBltTest.pdb

     文件      14328  2013-07-02 21:26  BitBltTest\BitBltTest\bin\Debug\BitBltTest.vshost.exe

     文件        490  2009-06-11 05:14  BitBltTest\BitBltTest\bin\Debug\BitBltTest.vshost.exe.manifest

     文件       3766  2013-07-02 19:47  BitBltTest\BitBltTest\BitBltTest.csproj

     文件       6104  2013-07-02 21:26  BitBltTest\BitBltTest\Form1.cs

     文件       4690  2013-07-02 20:07  BitBltTest\BitBltTest\Form1.Designer.cs

     文件       6398  2013-07-02 20:07  BitBltTest\BitBltTest\Form1.resx

     文件        817  2013-07-02 21:26  BitBltTest\BitBltTest\obj\Debug\BitBltTest.csproj.FileListAbsolute.txt

     文件        847  2013-07-02 20:07  BitBltTest\BitBltTest\obj\Debug\BitBltTest.csproj.GenerateResource.Cache

     文件      11264  2013-07-02 21:26  BitBltTest\BitBltTest\obj\Debug\BitBltTest.exe

     文件        180  2013-07-02 20:07  BitBltTest\BitBltTest\obj\Debug\BitBltTest.Form1.resources

     文件      26112  2013-07-02 21:26  BitBltTest\BitBltTest\obj\Debug\BitBltTest.pdb

     文件        180  2013-07-02 19:47  BitBltTest\BitBltTest\obj\Debug\BitBltTest.Properties.Resources.resources

     文件        491  2013-07-02 19:03  BitBltTest\BitBltTest\Program.cs

     文件       1352  2013-07-02 19:03  BitBltTest\BitBltTest\Properties\AssemblyInfo.cs

     文件       2870  2013-07-02 19:03  BitBltTest\BitBltTest\Properties\Resources.Designer.cs

     文件       5612  2013-07-02 19:03  BitBltTest\BitBltTest\Properties\Resources.resx

     文件       1095  2013-07-02 19:03  BitBltTest\BitBltTest\Properties\Settings.Designer.cs

     文件        249  2013-07-02 19:03  BitBltTest\BitBltTest\Properties\Settings.settings

     文件        920  2013-07-02 19:04  BitBltTest\BitBltTest.sln

    ..A..H.      7680  2013-07-02 19:04  BitBltTest\BitBltTest.suo

     目录          0  2013-07-02 19:04  BitBltTest\BitBltTest\obj\Debug\TempPE

     目录          0  2013-07-02 19:56  BitBltTest\BitBltTest\bin\Debug

     目录          0  2013-07-02 21:26  BitBltTest\BitBltTest\obj\Debug

     目录          0  2013-07-02 19:03  BitBltTest\BitBltTest\bin

     目录          0  2013-07-02 19:03  BitBltTest\BitBltTest\obj

     目录          0  2013-07-02 19:03  BitBltTest\BitBltTest\Properties

     目录          0  2013-07-02 21:26  BitBltTest\BitBltTest

     目录          0  2013-07-02 19:04  BitBltTest

............此处省略3个文件信息

评论

共有 条评论