在内存中画图实现双缓冲
来源:互联网 发布:手机只能用2g网络 编辑:程序博客网 时间:2024/05/21 13:59
在C++builder中防止画图闪烁,一般需要用到双缓冲,即在内存中画图,然后复制到界面上去。
.h文件如下:
class TForm1 : public TForm{ __published:// IDE-managed Components TTimer *Timer1; TImage *Image1; void __fastcall Timer1Timer(TObject *Sender); private:// User declarations ULONG_PTR GdiplusToken; //GDI初始化相关 Gdiplus::GdiplusStartupInput GdiplusStartupInput; public:// User declarations __fastcall TForm1(TComponent* Owner); __fastcall ~TForm1(void); HDC m_hdcMemory; //内存句柄 HDC hdcTemp; //设备上下文句柄 HBITMAP hBitMap; //位图句柄};//---------------------------------------------------------------------------extern PACKAGE TForm1 *Form1;.cpp文件中调用GDI+画图,代码如下:
#include <vcl.h>#pragma hdrstop#include <math.h> #include <algorithm>using std::min;using std::max;#include "gdiplus.h"using namespace Gdiplus;#include "Unit1.h"//---------------------------------------------------------------------------#pragma package(smart_init)#pragma resource "*.dfm"TForm1 *Form1;#pragma warn -inl#pragma warn -8022Gdiplus::Graphics *g;//---------------------------------------------------------------------------__fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner){ Image1->Parent->DoubleBuffered = true; GdiplusStartup(&GdiplusToken, &GdiplusStartupInput, NULL); //初始化GDI+ //--------------------------------------- hdcTemp = GetDC(0);//设备上下文环境句柄 m_hdcMemory = CreateCompatibleDC(hdcTemp);//内存环境句柄 hBitMap = CreateCompatibleBitmap(hdcTemp,450,265);//该函数创建与指定的设备环境相关的设备兼容的位图 SelectObject(m_hdcMemory, hBitMap);//该函数选择一对象到指定的设备上下文环境中 g= new Gdiplus::Graphics(m_hdcMemory); }//---------------------------------------------------------------------------__fastcall TForm1::~TForm1(void) { GdiplusShutdown(GdiplusToken); // 关闭GDI+ ReleaseDC(0, hdcTemp); hdcTemp = NULL; DeleteObject(hBitMap); DeleteDC(m_hdcMemory); m_hdcMemory = NULL;}//---------------------------------------------------------------------------void __fastcall TForm1::Timer1Timer(TObject *Sender){ const static int OX = 200, OY = 200;const static REAL C = 140;const static REAL PI = 3.14;static REAL offset = 0;POINT p[4];REAL k[4]; //==============================// 生成正文形四角的新坐标值for (int i=0; i < 4; i++){ k[i] = offset + (PI / 2) * i; p[i].x = (int)OX + C*sin(k[i]); p[i].y = (int)OY + C*cos(k[i]);}g->SetSmoothingMode(SmoothingModeHighQuality); //高画质、低速// 重新填充背景SolidBrush brush(Color::Color(100,0,0));//画刷Pen pen(Color::Color(255, 0, 0), 1);//画笔g->FillRectangle(&brush, 0, 0, ClientWidth, ClientHeight); //画矩形Gdiplus::Point point1(p[0].x, p[0].y);//设置点坐标Gdiplus::Point point2(p[1].x, p[1].y);Gdiplus::Point point3(p[2].x, p[2].y);Gdiplus::Point point4(p[3].x, p[3].y);Gdiplus::Point point5(p[0].x, p[0].y);// 在新坐标绘画正方形Gdiplus::Point points[] = {point1, point2, point3, point4, point5};g->DrawLines(&pen, points, 5);//画线offset += 0.1; BitBlt(Image1->Canvas->Handle, 0, 0, 600, 600, m_hdcMemory, 0, 0, SRCCOPY);//复制内存中的图像到界面上去 Image1->Repaint();}
0 0
- 在内存中画图实现双缓冲
- 怎样在内存缓冲中画图(zz)
- 怎样在内存缓冲中画图
- 怎样在内存缓冲中画图
- 怎样在内存缓冲中画图
- VC怎样在内存缓冲中画图
- VC怎样在内存缓冲中画图
- 怎样在内存缓冲中画图 转载 原作者 相生昌
- 使用Qt在内存中画图
- 使用Qt在内存中画图
- 在内存中画图,保存为bmp
- 画图实现双缓冲
- 画图实现双缓冲
- VC++控制台应用程序下使用GDI在内存中画图
- QT实现双缓冲画图
- MFC中双缓冲画图
- CScrollView中双缓冲画图
- CScrollView中双缓冲画图
- 万圣节福利:红孩儿3D引擎开发课程《3ds max导出插件初步》
- JSP自定义标签
- 带权二分图的最优匹配 Kuhn-Munkres算法
- ffmpeg转yuv到h264
- EF Code First 一对多、多对多关联,如何加载子集合?
- 在内存中画图实现双缓冲
- 嵌入式 uboot引导kernel,kernel引导fs
- 镶嵌数据集工具小结(五)镶嵌数据集的属性 Ⅱ
- Using rsyslog mmnormalize module effectively with Adiscon LogAnalyzer
- iBatiS中遇到的sql上的问题小结
- 学习方法
- 关于Hibernate
- android中选择控件与选择界面自然过度效果的实现--一种新的交互设计
- 校园双选会,你都懂么