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. Bmp vs Bitmap
Forum Updated to NodeBB v4.3 + New Features

Bmp vs Bitmap

Scheduled Pinned Locked Moved General and Desktop
10 Posts 2 Posters 3.4k 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.
  • N Offline
    N Offline
    norrbotten68
    wrote on last edited by
    #1

    Hi.
    I tried to find how create bmp file (header, palette information, data ) on Qt but only can find codes in plane C++. I can't use them (maybe becouse I just started with Qt) becouse of just this line @ (BYTE* pBitmapBits, LONG lWidth, LONG lHeight,WORD wBitsPerPixel, LPCTSTR lpszFileName )@ contains a lot of variables that not accepts by Qt. In documentation I found some thing that calls QBitmap but can't find any examples how to actually create bmp with it. Any help will be appreciated.

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

      You don't have to resort to windows api functions.
      Here's a simplest example:

      @
      QPixmap pixmap(400,300);
      QPainter painter(&pixmap);

      //do some drawing
      painter.fillRect(0,0,400,300, Qt::red);
      painter.drawRect(10,10,100,100);

      //save to file
      pixmap.save("C:\file.bmp");
      @

      1 Reply Last reply
      0
      • N Offline
        N Offline
        norrbotten68
        wrote on last edited by
        #3

        this is useful if you will create bitmap from image . I need to do opposite create bitmap from data file and show it as image. In that case data represents by different colors depending of data value and palette in bmp file. I do that with Net and I sure that it possible to do with Qt too.

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

          Sorry, but I'm a little confused. First you said you want to create a bmp and now that you want to read from it to create a Qt image?
          If so then it's just
          @
          QPixmap p("C:\file.bmp");
          @
          I think you need to be more precise what is bitmap and what is image because QImage, QBitmap, bitmap and .bmp file are 4 totally different things.

          1 Reply Last reply
          0
          • N Offline
            N Offline
            norrbotten68
            wrote on last edited by
            #5

            sorry I mean to confuse any one. I just don't know where to start and which tool use for my porosity, I try to move my application from Net to Qt and this is really frustrated when something that you could do before you need to discover again

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

              I get that. It's always like that when you change language/library.
              So what do you want to do actually (leaving language/library specifics aside)?

              1 Reply Last reply
              0
              • N Offline
                N Offline
                norrbotten68
                wrote on last edited by
                #7

                I reserve data from some devise that have to be presented in the way user can analyze it.

                1 Reply Last reply
                0
                • N Offline
                  N Offline
                  norrbotten68
                  wrote on last edited by
                  #8

                  incoming data shows as bitmap . I don't use 24 bit bitmap to be able quickly change colors just by changing palette . User can see data as a picture .

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

                    Ok, so we can assume you have just an input array of 8-bit values. Something like unsigned char* or BYTE* or PBYTE or whatever alias your input uses. Either way it's just a pointer do the actual 8bit values.

                    You can create an image from it using "QImage":http://qt-project.org/doc/qt-5/qimage.html#QImage-4, for example:
                    @
                    //get these from whatever your input is
                    int width = ...
                    int height = ...
                    uchar* data = ...

                    //you can use this instance as long as the data pointer is valid
                    QImage img(data, width, height, QImage::Format_Indexed8);
                    @
                    With this you can do any number of stuff, eg. change any palette color using "setColor":http://qt-project.org/doc/qt-5/qimage.html#setColor or the whole palette using "setColorTable":http://qt-project.org/doc/qt-5/qimage.html#setColorTable
                    You can use it to display in a label eg.
                    @
                    ui.someLabel->setPixmap(QPixmap::fromImage(img));
                    @
                    or paint it in a paintEvent of some widget:
                    @
                    QPainter p(this);
                    p.drawImage(x, y, img);
                    @
                    and so on...

                    1 Reply Last reply
                    0
                    • N Offline
                      N Offline
                      norrbotten68
                      wrote on last edited by
                      #10

                      Thank you very much. See you with next question.

                      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