Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to convert GDI bitmap to QPixmap
Forum Updated to NodeBB v4.3 + New Features

How to convert GDI bitmap to QPixmap

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 664 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • CesarC Offline
    CesarC Offline
    Cesar
    wrote on last edited by
    #1

    How to convert a GDI GpBitmap* to QPixmap?

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      There's no direct conversion, but QImage can be created from HBITMAP, so you can do it in 2 steps: create HBITMAP from GpBitmap and then create QImage out of that. Something like:

      Gdiplus::GpBitmap* gpBitmap = /* something */;
      HBITMAP bitmap {};
      Gdiplus::DllExports::GdipCreateHBITMAPFromBitmap(gpBitmap, &bitmap, Gdiplus::Color::Transparent);
      QImage image = QImage::fromHBITMAP(bitmap);
      DeleteObject(bitmap);
      

      Note that QImage::fromHBITMAP is available in Qt6.
      In Qt5 it was part of a separate module QtWinExtras: QtWin::imageFromHBITMAP()

      It's a bit of a waste because it's doing two conversions. If you care for performance the best would be to get access to the GpBitmap raw data and create QImage from that directly, but that's more work. The above is the lazy way.

      1 Reply Last reply
      1
      • CesarC Offline
        CesarC Offline
        Cesar
        wrote on last edited by Cesar
        #3

        Does it preserve transparency?

        get access to the GpBitmap raw data and create QImage from that directly

        Do you mean lockbits?

        Chris KawaC 1 Reply Last reply
        0
        • CesarC Cesar

          Does it preserve transparency?

          get access to the GpBitmap raw data and create QImage from that directly

          Do you mean lockbits?

          Chris KawaC Offline
          Chris KawaC Offline
          Chris Kawa
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Does it preserve transparency?

          I don't know. Check.

          Do you mean lockbits?

          Yeah, probably, although from what I understand it also does a copy and conversion to the format you specify, so maybe it's not worth it.,

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved