Duilib中将GDI换成GDI+

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);



目前只是初步测试工程,还要进一步完善。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值