I am using Qt3.
Would like to know how I can convert a HBitmap to a QPixmap?
Is it possible in Qt3? If not what are the alternatives?
Printable View
I am using Qt3.
Would like to know how I can convert a HBitmap to a QPixmap?
Is it possible in Qt3? If not what are the alternatives?
Why don't you use Qt4 instead of old abandon Qt3?
Hi,
try this;
yourPixmap = QPixmap::fromWinHBitmap( pixmap, QPixmap::PremultipliedAlpha);
this is code from Qt 4.4.3
Code:
{ // Verify size BITMAP bitmap_info; memset(&bitmap_info, 0, sizeof(BITMAP)); int res; QT_WA({ res = GetObjectW(bitmap, sizeof(BITMAP), &bitmap_info); } , { res = GetObjectA(bitmap, sizeof(BITMAP), &bitmap_info); }); if (!res) { qErrnoWarning("QPixmap::fromWinHBITMAP(), failed to get bitmap info"); } int w = bitmap_info.bmWidth; int h = bitmap_info.bmHeight; BITMAPINFO bmi; memset(&bmi, 0, sizeof(bmi)); bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); bmi.bmiHeader.biWidth = w; bmi.bmiHeader.biHeight = -h; bmi.bmiHeader.biPlanes = 1; bmi.bmiHeader.biBitCount = 32; bmi.bmiHeader.biCompression = BI_RGB; bmi.bmiHeader.biSizeImage = w * h * 4; QImage result; // Get bitmap bits uchar *data = (uchar *) qMalloc(bmi.bmiHeader.biSizeImage); if (GetDIBits(qt_win_display_dc(), bitmap, 0, h, data, &bmi, DIB_RGB_COLORS)) { uint mask = 0; if (format == NoAlpha) { mask = 0xff000000; } // Create image and copy data into image. if (!image.isNull()) { // failed to alloc? int bytes_per_line = w * sizeof(QRgb); for (int y=0; y<h; ++y) { QRgb *dest = (QRgb *) image.scanLine(y); const QRgb *src = (const QRgb *) (data + y * bytes_per_line); for (int x=0; x<w; ++x) { dest[x] = src[x] | mask; } } } result = image; } else { qWarning("QPixmap::fromWinHBITMAP(), failed to get bitmap bits"); } qFree(data); return fromImage(result); }
Thanks Spirit for the information, I was able to resolve it.
Appreciate the time of everyone who replied to my post :)