Skip to content

Instantly share code, notes, and snippets.

@lniwn
Last active January 18, 2016 03:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lniwn/513a00644b4d7a0839ab to your computer and use it in GitHub Desktop.
Save lniwn/513a00644b4d7a0839ab to your computer and use it in GitHub Desktop.
gdi 绘制图像
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