2013-04-14 56 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爲例。