Gdi+与双缓冲的图片显示(应用篇)
2015-09-24 10:49
417 查看
一、专词理解</span>
Gdi+:负责Windows绘图的API。
双缓冲:绘图操作和显示分开,绘制完成后,直接拷贝显示。
二、MFC处理流程
1.准备GDI+接口
包含头文件:
2.构建双缓冲
3. OnDraw里绘图
三、效果及源代码
代码地址:https://github.com/lk547256398/ImageProcessing
Gdi+:负责Windows绘图的API。
双缓冲:绘图操作和显示分开,绘制完成后,直接拷贝显示。
二、MFC处理流程
1.准备GDI+接口
包含头文件:
#include <gdiplus.h> using namespace Gdiplus; #pragma comment (lib,"Gdiplus.lib")
构造函数里GDI+初始化(容易遗忘掉的地方):
CImageProcessingView::CImageProcessingView(): m_iImgHeight(0), m_iImgWidth(0) { // TODO: 在此处添加构造代码 // Initialize GDI+. GdiplusStartupInput gdiplusStartupInput; ULONG_PTR gdiplusToken; GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL); }
</pre><pre>
2.构建双缓冲
private: CBitmap m_bitmapMemory;// 内存位图 CDC m_dcMemory; // 内存dc int m_iImgHeight;// 图片高 int m_iImgWidth;// 图片宽 // 操作 public: void CreateMemoryDC(); // 创建位图和内存dc void ReleaseMemoryDC(); // 释放位图和内存dc
void CImageProcessingView::CreateMemoryDC() { CImageProcessingDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); if (!pDoc) return; wchar_t strImg[1024]; MultiByteToWideChar(CP_ACP, NULL, pDoc->GetImagePath().c_str(),\ 1024, strImg, 1024); Image img(strImg); m_iImgWidth = img.GetWidth(); m_iImgHeight = img.GetHeight(); CClientDC dc(this); m_dcMemory.CreateCompatibleDC(&dc); m_bitmapMemory.CreateCompatibleBitmap(&dc, m_iImgWidth, m_iImgHeight); SelectObject(m_dcMemory, m_bitmapMemory); // 绘图 Graphics graphics(m_dcMemory); graphics.DrawImage(&img, 0, 0); } void CImageProcessingView::ReleaseMemoryDC() { m_bitmapMemory.DeleteObject(); m_dcMemory.DeleteDC(); }
3. OnDraw里绘图
void CImageProcessingView::OnDraw(CDC* pDC) { CImageProcessingDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); if (!pDoc) return; if (pDoc->GetImagePath() == "") return; // 获取客户区大小 CRect rect; GetClientRect(&rect); int nWidth = m_iImgWidth > rect.Width() ? m_iImgWidth : rect.Width(); int nHeight = m_iImgHeight > rect.Height() ? m_iImgHeight : rect.Height(); // 滚动窗口 CSize sizeTotal; sizeTotal.cx = nWidth; sizeTotal.cy = nHeight; SetScrollSizes(MM_TEXT, sizeTotal); pDC->BitBlt(0, 0, nWidth, nHeight, &m_dcMemory, 0, 0, SRCCOPY); }
三、效果及源代码
代码地址:https://github.com/lk547256398/ImageProcessing
相关文章推荐
- C#图像处理之霓虹效果实现方法
- C#图像亮度调整的方法
- C#实现图像锐化的方法
- C#图像透明度调整的方法
- C#数字图象处理之图像灰度化方法
- C#图像处理之头发检测的方法
- C#常用GDI+文字操作汇总
- C#图像处理之图像目标质心检测的方法
- C#实现图像反色的方法
- 从jsp发送动态图像
- C#数字图像处理之图像缩放的方法
- Visual C++中MFC消息的分类
- C++将CBitmap类中的图像保存到文件的方法
- 解析在WTL下使用双缓冲的实现方法
- MFC中Radio Button的用法详解
- MFC对话框中添加状态栏的方法
- MFC创建右键弹出菜单的方法
- MFC中动态创建控件以及事件响应实现方法
- C++ 关于MFC多线程编程的注意事项
- MFC程序对文件的处理方法