| 16 | } |
| 17 | |
| 18 | QImage 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 | |
| 50 | bool Utils::initWuwaHwnd(){ |
| 51 | QMutexLocker locker(&m_locker); |