Results 1 to 7 of 7

Thread: Converting from HBitmap to a QPixmap

  1. #1
    Join Date
    Feb 2009
    Posts
    45
    Thanks
    3
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Windows

    Default Converting from HBitmap to a QPixmap

    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?
    Last edited by qtUser500; 2nd March 2009 at 20:55.

  2. #2
    Join Date
    Mar 2008
    Location
    Houston, Texas, USA
    Posts
    277
    Thanks
    9
    Thanked 17 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Maemo/MeeGo

    Default Re: Converting from HBitmap to a QPixmap

    Why don't you use Qt4 instead of old abandon Qt3?
    Qt-4.7.3 | Gentoo ~amd64 | KDE-4.7
    Aki IRC Client for KDE4 | Qt Documentation

  3. #3
    Join Date
    Dec 2008
    Location
    Istanbul, TURKEY
    Posts
    537
    Thanks
    14
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default Re: Converting from HBitmap to a QPixmap

    Hi,

    try this;

    yourPixmap = QPixmap::fromWinHBitmap( pixmap, QPixmap::PremultipliedAlpha);

  4. #4
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Converting from HBitmap to a QPixmap

    Quote Originally Posted by zgulser View Post
    Hi,

    try this;

    yourPixmap = QPixmap::fromWinHBitmap( pixmap, QPixmap::PremultipliedAlpha);
    there is no such method in Qt3.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  5. #5
    Join Date
    Feb 2009
    Posts
    45
    Thanks
    3
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Windows

    Default Re: Converting from HBitmap to a QPixmap

    Quote Originally Posted by spirit View Post
    there is no such method in Qt3.
    Yes I noticed no method like that in Qt3.

    Any suggestions on how to convert a HBitmap to some other image form after which it can be converted to QPixmap.

  6. #6
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Converting from HBitmap to a QPixmap

    this is code from Qt 4.4.3
    Qt Code:
    1. QPixmap QPixmap::fromWinHBITMAP(HBITMAP bitmap, HBitmapFormat format)
    2. {
    3. // Verify size
    4. BITMAP bitmap_info;
    5. memset(&bitmap_info, 0, sizeof(BITMAP));
    6.  
    7. int res;
    8. QT_WA({
    9. res = GetObjectW(bitmap, sizeof(BITMAP), &bitmap_info);
    10. } , {
    11. res = GetObjectA(bitmap, sizeof(BITMAP), &bitmap_info);
    12. });
    13.  
    14. if (!res) {
    15. qErrnoWarning("QPixmap::fromWinHBITMAP(), failed to get bitmap info");
    16. return QPixmap();
    17. }
    18. int w = bitmap_info.bmWidth;
    19. int h = bitmap_info.bmHeight;
    20.  
    21. BITMAPINFO bmi;
    22. memset(&bmi, 0, sizeof(bmi));
    23. bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
    24. bmi.bmiHeader.biWidth = w;
    25. bmi.bmiHeader.biHeight = -h;
    26. bmi.bmiHeader.biPlanes = 1;
    27. bmi.bmiHeader.biBitCount = 32;
    28. bmi.bmiHeader.biCompression = BI_RGB;
    29. bmi.bmiHeader.biSizeImage = w * h * 4;
    30.  
    31. QImage result;
    32. // Get bitmap bits
    33. uchar *data = (uchar *) qMalloc(bmi.bmiHeader.biSizeImage);
    34. if (GetDIBits(qt_win_display_dc(), bitmap, 0, h, data, &bmi, DIB_RGB_COLORS)) {
    35.  
    36. QImage::Format imageFormat = QImage::Format_ARGB32_Premultiplied;
    37. uint mask = 0;
    38. if (format == NoAlpha) {
    39. imageFormat = QImage::Format_RGB32;
    40. mask = 0xff000000;
    41. }
    42.  
    43. // Create image and copy data into image.
    44. QImage image(w, h, imageFormat);
    45. if (!image.isNull()) { // failed to alloc?
    46. int bytes_per_line = w * sizeof(QRgb);
    47. for (int y=0; y<h; ++y) {
    48. QRgb *dest = (QRgb *) image.scanLine(y);
    49. const QRgb *src = (const QRgb *) (data + y * bytes_per_line);
    50. for (int x=0; x<w; ++x) {
    51. dest[x] = src[x] | mask;
    52. }
    53. }
    54. }
    55. result = image;
    56. } else {
    57. qWarning("QPixmap::fromWinHBITMAP(), failed to get bitmap bits");
    58. }
    59. qFree(data);
    60. return fromImage(result);
    61. }
    To copy to clipboard, switch view to plain text mode 
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  7. #7
    Join Date
    Feb 2009
    Posts
    45
    Thanks
    3
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Windows

    Default Re: Converting from HBitmap to a QPixmap

    Thanks Spirit for the information, I was able to resolve it.
    Appreciate the time of everyone who replied to my post

Similar Threads

  1. QPixmap -> HICON trouble.
    By krivenok in forum Qt Programming
    Replies: 1
    Last Post: 11th August 2006, 15:51
  2. QPixmap and HBITMAP
    By ToddAtWSU in forum Qt Programming
    Replies: 1
    Last Post: 21st June 2006, 16:24

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.