Gdiplus位图错误



我正在尝试将HBITMAP转换为Gdiplus位图。我的代码是得到一些我从谷歌找到的代码截图,并把它放在一个HBITMAP。我想使用Gdiplus获得rgb值(特别是argb)。

获得屏幕截图的代码工作文件,但是将HBITMAP转换为Bitmap的那行抛出了大量疯狂的链接器错误。下面是我的代码:

HDC hScreenDC = CreateDC((LPCWSTR)"DISPLAY", NULL, NULL, NULL);     
// and a device context to put it in
HDC hMemoryDC = CreateCompatibleDC(hScreenDC);
int x = GetDeviceCaps(hScreenDC, HORZRES);
int y = GetDeviceCaps(hScreenDC, VERTRES);
// maybe worth checking these are positive values
HBITMAP hBitmap = CreateCompatibleBitmap(hScreenDC, x, y);
// get a new bitmap
HBITMAP hOldBitmap = (HBITMAP)SelectObject(hMemoryDC, hBitmap);
BitBlt(hMemoryDC, 0, 0, 1920, 1080, hScreenDC, 0, 0, SRCCOPY);
hBitmap = (HBITMAP)SelectObject(hMemoryDC, hOldBitmap);
// clean up
DeleteDC(hMemoryDC);
DeleteDC(hScreenDC);
Gdiplus::Bitmap* pBitmap = Gdiplus::Bitmap::FromHBITMAP( hBitmap, NULL ); // <-- problem line

liner错误是LNK2019,并说:在函数"public: static void __cdecl Gdiplus::GdiplusBase::operator delete(void *)"中引用的未解析的外部符号_GdipFree@4(? ? 3 gdiplusbase@gdiplus@@saxpax@z)

我已经包含了gdiplus.h, windows.h和#define GDIPVER 0x110

你知道怎么解决这个问题吗?

首先要检查-您是否链接到gdiplus.lib?这很可能就是问题所在。

还要确保在开始使用GDI+函数之前的某个时刻调用了GdiplusStartup()。

您需要将您的项目链接到gdiplus.lib

#include "Gdiplus.h"
#pragma comment(lib,"gdiplus.lib")

最新更新