MCPcopy Create free account
hub / github.com/Hashiao/wuwaBackendTool / HBitmapToQImage

Method HBitmapToQImage

utils.cpp:18–48  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

16}
17
18QImage Utils::HBitmapToQImage(HBITMAP hBitmap, HDC hDC) {
19 try {
20 BITMAP bmp;
21 GetObject(hBitmap, sizeof(BITMAP), &bmp);
22
23 // 创建 QImage 对象
24 QImage image(bmp.bmWidth, bmp.bmHeight, QImage::Format_ARGB32);
25
26 BITMAPINFOHEADER bi;
27 bi.biSize = sizeof(BITMAPINFOHEADER);
28 bi.biWidth = bmp.bmWidth;
29 bi.biHeight = -bmp.bmHeight; // Top-down DIB
30 bi.biPlanes = 1;
31 bi.biBitCount = 32;
32 bi.biCompression = BI_RGB;
33 bi.biSizeImage = 0;
34 bi.biXPelsPerMeter = 0;
35 bi.biYPelsPerMeter = 0;
36 bi.biClrUsed = 0;
37 bi.biClrImportant = 0;
38
39 // 获取位图数据并填充到 QImage
40 GetDIBits(hDC, hBitmap, 0, bmp.bmHeight, image.bits(), (BITMAPINFO*)&bi, DIB_RGB_COLORS);
41
42 return image;
43 } catch (...) {
44 qWarning() << "failed to convert HBitmapToQImage";
45 return QImage();
46 }
47
48}
49
50bool Utils::initWuwaHwnd(){
51 QMutexLocker locker(&m_locker);

Callers

nothing calls this directly

Calls 1

bitsMethod · 0.80

Tested by

no test coverage detected