Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QImage from HBITMAP

In my windows-only program, I use a third-party library, which returns a HBITMAP.

Is there a way to initialize a QImage from its contents, i.e. to convert it to a QImage?

like image 408
sashoalm Avatar asked Jan 28 '13 18:01

sashoalm


1 Answers

This is the way to do it for Qt 4 (QtGui):

QImage image(QPixmap::fromWinHBITMAP(hBitmap).toImage());

This is the way to do it for Qt 5 (QtWinExtras):

QPixmap pixmap = QtWin::fromHBITMAP(hBitmap);
QImage image = pixmap.toImage();

// or

QtWin::imageFromHBITMAP(hdc, hBitmap, width, height)
like image 60
lpapp Avatar answered Sep 24 '22 00:09

lpapp