Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Game Development
  4. BMP display in QT c++
Forum Updated to NodeBB v4.3 + New Features

BMP display in QT c++

Scheduled Pinned Locked Moved Unsolved Game Development
6 Posts 4 Posters 4.2k Views 2 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.
  • S Offline
    S Offline
    shashi prasad
    wrote on last edited by
    #1

    Hi,

    i am trying to display BMP in QT with below code. bmp downloaded correctly but image is not displayed.

    fun(){

    std::string szUrl("http://guest:p2guest@192.168.55.3/contents/2/icon/0874T2.bmp");
    std::wstring wpathURL(szUrl.begin(), szUrl.end());
    char *recByte = contmgr->Download(wpathURL.c_str());
    QGraphicsScene scene;
    QGraphicsView view(&scene);
    QImage img;
    img.fromData(recByte); // READING DATA
    QPixmap pic;
    pic.fromImage(img);
    QGraphicsPixmapItem item(pic);
    scene.addItem(&item);
    view.show();
    

    }

    download function works fine, i have tested for other functionality.

    please suggest me how to display bmp, what is issue with this code.

    raven-worxR J.HilkJ 2 Replies Last reply
    0
    • S shashi prasad

      Hi,

      i am trying to display BMP in QT with below code. bmp downloaded correctly but image is not displayed.

      fun(){

      std::string szUrl("http://guest:p2guest@192.168.55.3/contents/2/icon/0874T2.bmp");
      std::wstring wpathURL(szUrl.begin(), szUrl.end());
      char *recByte = contmgr->Download(wpathURL.c_str());
      QGraphicsScene scene;
      QGraphicsView view(&scene);
      QImage img;
      img.fromData(recByte); // READING DATA
      QPixmap pic;
      pic.fromImage(img);
      QGraphicsPixmapItem item(pic);
      scene.addItem(&item);
      view.show();
      

      }

      download function works fine, i have tested for other functionality.

      please suggest me how to display bmp, what is issue with this code.

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @shashi-prasad said in BMP display in QT c++:

      QImage img;
      img.fromData(recByte); // READING DATA
      QPixmap pic;
      pic.fromImage(img);

      Not related to your issue, but there is no need to first create a QImage and then a QPixmap. You can create a QPixmap directly.

      For your issue make sure have the imageplugins deployed/available.
      What does the following return?

      qDebug() << QImageReader ::supportedImageFormats()
      

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • S shashi prasad

        Hi,

        i am trying to display BMP in QT with below code. bmp downloaded correctly but image is not displayed.

        fun(){

        std::string szUrl("http://guest:p2guest@192.168.55.3/contents/2/icon/0874T2.bmp");
        std::wstring wpathURL(szUrl.begin(), szUrl.end());
        char *recByte = contmgr->Download(wpathURL.c_str());
        QGraphicsScene scene;
        QGraphicsView view(&scene);
        QImage img;
        img.fromData(recByte); // READING DATA
        QPixmap pic;
        pic.fromImage(img);
        QGraphicsPixmapItem item(pic);
        scene.addItem(&item);
        view.show();
        

        }

        download function works fine, i have tested for other functionality.

        please suggest me how to display bmp, what is issue with this code.

        J.HilkJ Offline
        J.HilkJ Offline
        J.Hilk
        Moderators
        wrote on last edited by
        #3

        @shashi-prasad

        QImage QImage::fromData(const uchar *data, int size, const char *format = Q_NULLPTR) is a static function that returns a QImage

        QImage img;
        img.fromData(recByte); // READING DATA

        has no effect on img it will remain an null-image

        try

        QImage img = QImage::fromData(recByte);


        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


        Q: What's that?
        A: It's blue light.
        Q: What does it do?
        A: It turns blue.

        1 Reply Last reply
        1
        • S Offline
          S Offline
          shashi prasad
          wrote on last edited by
          #4

          output of qDebug() << QImageReader ::supportedImageFormats(); is

          ("bmp", "cur", "dds", "gif", "icns", "ico", "jp2", "jpeg", "jpg", "pbm", "pgm", "png", "ppm", "svg", "svgz", "tga", "tif", "tiff", "wbmp", "webp", "xbm", "xpm")

          output of qDebug()<<"recByte============="<<img.size(); is

          recByte============= QSize(0, 0)

          i think something wrong so it is showing 0,0.

          i used as QImage img = QImage::fromData(recByte);

          still output of qDebug()<<"recByte============="<<img.size(); is
          recByte============= QSize(0, 0)

          please suggest me.

          J.HilkJ 1 Reply Last reply
          0
          • S shashi prasad

            output of qDebug() << QImageReader ::supportedImageFormats(); is

            ("bmp", "cur", "dds", "gif", "icns", "ico", "jp2", "jpeg", "jpg", "pbm", "pgm", "png", "ppm", "svg", "svgz", "tga", "tif", "tiff", "wbmp", "webp", "xbm", "xpm")

            output of qDebug()<<"recByte============="<<img.size(); is

            recByte============= QSize(0, 0)

            i think something wrong so it is showing 0,0.

            i used as QImage img = QImage::fromData(recByte);

            still output of qDebug()<<"recByte============="<<img.size(); is
            recByte============= QSize(0, 0)

            please suggest me.

            J.HilkJ Offline
            J.HilkJ Offline
            J.Hilk
            Moderators
            wrote on last edited by J.Hilk
            #5

            @shashi-prasad
            my guess would be your recByte is empty or has an invalid header. You should check that.

            Edit: Additional Info

            if recByte is not empty check the 14 first Bytes.
            0-1 => The header field used to identify the BMP
            2-5 => Size of the BMP
            6-9 => Reserved for the application that created the bmp file
            10-14 => starting address, of the byte where the bitmap image data (pixel array) can be found.


            Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


            Q: What's that?
            A: It's blue light.
            Q: What does it do?
            A: It turns blue.

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Hi,

              Likely related to this thread.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              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