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. Display raw image data
QtWS25 Last Chance

Display raw image data

Scheduled Pinned Locked Moved General and Desktop
14 Posts 3 Posters 14.5k Views
  • 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.
  • V Offline
    V Offline
    vinaykutsa
    wrote on last edited by
    #5

    My code is here as under:

    @#include "mainwindow.h"
    #include "ui_mainwindow.h"

    MainWindow::MainWindow(QWidget parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    QLabel
    defaultCentralWidget = new QLabel( this );
    defaultCentralWidget->setPixmap( QPixmap( ":Image.png") );
    defaultCentralWidget->setAlignment( Qt::AlignCenter );
    ui->tabWidget->addTab(defaultCentralWidget, "Image");

    ui->setupUi(this);
    

    }

    MainWindow::~MainWindow()
    {
    delete ui;
    }@

    Image.png is in the same location as the this source file.
    Application fails. Please let me know where am I going wrong.

    1 Reply Last reply
    0
    • F Offline
      F Offline
      fluca1978
      wrote on last edited by
      #6

      I'm not sure of, but I think setupUI should be the first call. Then you have to ensure that Image.png is in the application resources, since you are using a path with the semicolon.
      What error do you get exactly?

      1 Reply Last reply
      0
      • V Offline
        V Offline
        vinaykutsa
        wrote on last edited by
        #7

        Application simple failed at run time. A window with message insisting to debug appears. I was not able figure out even while debugging. However for the time being I have removed using forms and have done the implemenation manually. So things work.

        Well, my actually intention was to display the raw image data. My code is here below:
        @ QByteArray imgData;
        QFile file("img.raw");
        if (!file.open(QIODevice::ReadOnly))
        {
        printf("Failed\n");
        exit(1);
        }
        qDebug("File Size: %d",file.bytesAvailable());
        imgData = file.readAll();
        qDebug("%d",imgData.size());
        QImage rawImg;
        bool falg = rawImg.loadFromData(imgData);
        qDebug("%d", falg);
        QPixmap pmap(555, 313);
        pmap.fill();
        QPainter painter;
        painter.begin(&pmap);
        painter.drawImage(0,0,rawImg);
        painter.end();
        QLabel *myLabel = new QLabel;
        myLabel->setPixmap(pmap);
        myLabel->show();@

        The file img.raw, is just a matrix of size 555X315 holding all pixel values. I understand that loadfromdata requires standard image format and hence my code will obviously not work.

        Please guide me what additional changes or implementation are to be done to get this working. I have referred to this link: http://doc.qt.nokia.com/qq/qq17-imageio.html

        Can article mentioned in the above link solve my problem. Please Guide. I would like to know if my approach is right.
        Thank you.

        1 Reply Last reply
        0
        • F Offline
          F Offline
          fluca1978
          wrote on last edited by
          #8

          What are messages displayed from qDebug()?
          Moreover why are you not using the simpler operatore << with qDebug()? and you are displaying a boolean as an integer. Anyway, I don't know why your application is crashing, post some more info.

          1 Reply Last reply
          0
          • G Offline
            G Offline
            goetz
            wrote on last edited by
            #9

            What's the format of your "raw image"? Usually the term raw image refers to the unformatted data that you get out of high end digicams. I'm not sure if that's what you have.

            The docs of QImage::loadFromData() state clearly:

            bq. Loads an image from the first len bytes of the given binary data. Returns true if the image was successfully loaded; otherwise returns false.
            The loader attempts to read the image using the specified format, e.g., PNG or JPG. If format is not specified (which is the default), the loader probes the file for a header to guess the file format.

            http://www.catb.org/~esr/faqs/smart-questions.html

            1 Reply Last reply
            0
            • V Offline
              V Offline
              vinaykutsa
              wrote on last edited by
              #10

              The raw image doesn't have a format as such (PNG, JPG). I just have pixel data. I understand the code, I have actually shown in the thread will certainly fail.

              I would like to understand how to display or render/paint/display this pixel data.

              1 Reply Last reply
              0
              • G Offline
                G Offline
                goetz
                wrote on last edited by
                #11

                The supported image types of QImage are "listed here":http://doc.qt.nokia.com/4.7/qimage.html#reading-and-writing-image-files. If you want to read other formats, you will have to write your own plugin.

                http://www.catb.org/~esr/faqs/smart-questions.html

                1 Reply Last reply
                0
                • V Offline
                  V Offline
                  vinaykutsa
                  wrote on last edited by
                  #12

                  Right... Thank you so much. And I believe this is the reference for writing a plugin: http://doc.qt.nokia.com/qq/qq17-imageio.html

                  Thank you once again.

                  1 Reply Last reply
                  0
                  • G Offline
                    G Offline
                    goetz
                    wrote on last edited by
                    #13

                    Yes, that's a good starting point.

                    http://www.catb.org/~esr/faqs/smart-questions.html

                    1 Reply Last reply
                    0
                    • V Offline
                      V Offline
                      vinaykutsa
                      wrote on last edited by
                      #14

                      @TARGET = rawPlugin
                      TEMPLATE = lib
                      CONFIG = qt plugin
                      VERSION = 1.0.0

                      HEADERS += argbhandler.h
                      SOURCES += argbplugin.cpp
                      argbhandler.cpp

                      target.path += D:/Software/QT/src-4.7.1/plugins/imageformats/imageformats
                      INSTALLS += target@

                      I'm using the example source provided in the link to learn. My project file is as above. I have modified the example source according to my requirement. I understand that I have to do:

                      bq. qmake file.pro
                      nmake
                      nmake install

                      I get an error saying :

                      bq. LINK : fatal error LNK1104: cannot open file 'rawPlugin.lib'

                      Please correct me, if I'm doing any thing wrong.
                      Thank you very much.

                      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