Last active
January 18, 2016 03:46
-
-
Save lniwn/513a00644b4d7a0839ab to your computer and use it in GitHub Desktop.
gdi 绘制图像
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Gdiplus::Bitmap* gdiplus_bitmap = Gdiplus::Bitmap::FromFile(headImagePath_.c_str()); | |
bool bOk = (gdiplus_bitmap && Gdiplus::Ok == gdiplus_bitmap->GetLastStatus()); | |
if (!bOk) { | |
return false; | |
} | |
HBITMAP hBmp; | |
if (Gdiplus::Ok != gdiplus_bitmap->GetHBITMAP(Gdiplus::Color::White, &hBmp)) | |
{ | |
return false; | |
} | |
BITMAP bmp = {0}; | |
int result = ::GetObject(hBmp, sizeof(bmp), &bmp); | |
if (result != sizeof(bmp)) | |
{ | |
return false; | |
} | |
BITMAPINFO bmpinfo = {0}; | |
bmpinfo.bmiHeader.biSize = sizeof(BITMAPINFO); | |
bmpinfo.bmiHeader.biWidth = bmp.bmWidth; | |
bmpinfo.bmiHeader.biHeight = bmp.bmHeight; | |
bmpinfo.bmiHeader.biBitCount = bmp.bmBitsPixel; | |
bmpinfo.bmiHeader.biCompression = BI_RGB; | |
bmpinfo.bmiHeader.biPlanes = bmp.bmPlanes; | |
::SetStretchBltMode(hdc, HALFTONE); | |
return bmp.bmHeight == ::StretchDIBits(hdc, kBrowserHeadWidgetLeft, kBrowserHeadWidgetTop, kBrowserHeadWidgetWidth, | |
kBrowserHeadWidgetHeight, 0, 0, gdiplus_bitmap->GetWidth(), gdiplus_bitmap->GetHeight(), bmp.bmBits, &bmpinfo, | |
DIB_RGB_COLORS, SRCCOPY); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment