2013-04-14 58 views
1

我试图将HBITMAP转换为Gdiplus位图。我的代码得到了一些我从google找到的代码并将其放入HBITMAP中的截图。我想要使​​用Gdiplus来获得rgb值(特别是argb)。Gdiplus位图错误

获取屏幕截图工作文件的代码,但将HBITMAP转换为位图的代码会引发大量疯狂的链接器错误。这里是我的代码:

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 

班轮错误是LNK2019,并说: 错误2错误LNK2019:解析外部符号_GdipFree @ 4在功能上引用的“市民:静态无效__cdecl Gdiplus :: GdiplusBase :: delete操作符(无效*)”(?? 3GdiplusBase @ Gdiplus @@ SAXPAX @ Z)

我已经包括gdiplus.h,WINDOWS.H和的#define GDIPVER量0x110

任何想法如何解决这一问题?

回答

0

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

此外,请确保您在开始使用GDI +功能之前的某个时间调用了GdiplusStartup()

0

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

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

以此结算post为例。