您的位置:首页 > 产品设计 > UI/UE

Duilib中将GDI换成GDI+

2017-01-31 11:04 609 查看
step1:在UIRend.cpp的文件头加入下面代码,目的是包含GDI+的头文件和库,以及定义提取图片的路径变量imagepath:

#include<corecrt_wstring.h>

#include <atlimage.h>

#include <gdiplus.h>    // GDI+库头文件,并在App头文件中声明相关变量

using namespace Gdiplus;

#pragma comment(lib, "gdiplus.lib")

#include <string>

std::string imagePath;

step2:在函数bool CRenderEngine::DrawImage(HDC hDC, CPaintManagerUI* pManager,

 const RECT& rcItem, const RECT& rcPaint,TDrawInfo& drawInfo)中加入以下代码。得到图片的路径。

imagePath = drawInfo.sDrawString;

imagePath.erase(0, 7);

imagePath.erase(imagePath.end()-2, imagePath.end());

std::string tempStr = pManager->GetInstancePath();

imagePath = tempStr + imagePath;

step3:在函数void CRenderEngine::DrawImage(HDC hDC, HBITMAP hBitmap, 
const RECT& rc, const RECT& rcPaint,
const RECT& rcBmpPart, const RECT& rcScale9, 
bool bAlpha,
BYTE uFade, bool bHole, bool bTiledX, bool bTiledY)的if (lpAlphaBlend && (bAlpha || uFade < 255))花括号内,替换第一个

lpAlphaBlend函数,将其改为:

Graphics graphics(hDC);

std::wstring widstr = std::wstring(imagePath.begin(), imagePath.end());

const wchar_t *pwidstr = widstr.c_str();
Image tempimage(pwidstr);
graphics.DrawImage(&tempimage, rcDest.left, rcDest.top, 
32, //测试时所用的矩形画图区域宽度
32);//测试时所用的矩形画图区域高度

或者使用CImage:

CImage cimage;
HRESULT hResult = cimage.Load(imagePath.c_str());
BOOL isSuccess = cimage.AlphaBlend(hDC,rcDest.left + 100,rcDest.top + 100);

目前只是初步测试工程,还要进一步完善。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Duilib