Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. [Solved] QImage works different on windows.
Forum Updated to NodeBB v4.3 + New Features

[Solved] QImage works different on windows.

Scheduled Pinned Locked Moved Qt Creator and other tools
9 Posts 2 Posters 2.3k 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.
  • M Offline
    M Offline
    ma_sadri
    wrote on last edited by
    #1

    Hi everybody.
    At first i should tell you that I’m totally new at Qt

    What is my problem:
    I was make a new project (Qt Widgets Application) on my mac, and make an application that use QImage for pixel manipulation, everything was ok until, I decided to run the same project on the windows Qt to make an executable file on windows, After build process get complete, I saw that pixel manipulation done in wrong way and it gives me the wrong image.
    I’m totally confused, codes are the same, forms are the same, no changes applied, but in the mac platform it works great and gives me what I want, but in the windows platform it doesn’t.

    I have 24 hours to fix this problem.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mcosta
      wrote on last edited by
      #2

      Hi,

      posting your code probably you can get more help

      Once your problem is solved don't forget to:

      • Mark the thread as SOLVED using the Topic Tool menu
      • Vote up the answer(s) that helped you to solve the issue

      You can embed images using (http://imgur.com/) or (http://postimage.org/)

      1 Reply Last reply
      0
      • M Offline
        M Offline
        ma_sadri
        wrote on last edited by
        #3

        [quote author="mcosta" date="1400580777"]Hi,

        posting your code probably you can get more help[/quote]

        Thanks for your reply.

        I've write something like this:
        @
        QRgb Black,nu;

        nu = qRgba(255,255,255,0);
        Black = qRgba(0,0,0,255);

        QImage inputimage;

        inputimage.load("....");

        QImage Finalimage(inputimage.width()*2,inputimage.height()*2,QImage::Format_ARGB32);

        for(row=0;row<inputimage.height();row++){
        for(column=0;column<inputimage.width();column++){
        if (inputimage.pixel(column,row)> 4286611584 | Finalimage.pixel(column,row)==0){ //White Pixel
        Finalimage.setPixel((column2),(row2),nu);
        Finalimage.setPixel((column2),(row2)+1,Black);
        Finalimage.setPixel((column2)+1,(row2),Black);
        Finalimage.setPixel((column2)+1,(row2)+1,nu);
        ...
        } else { //Black Pixel
        Finalimage.setPixel((column2),(row2),Black);
        Finalimage.setPixel((column2),(row2)+1,nu);
        Finalimage.setPixel((column2)+1,(row2),nu);
        Finalimage.setPixel((column2)+1,(row2)+1,Black);
        ...
        }
        ....
        }
        }

        Finalimage.save("...");
        @

        First i load an image then start to read every pixel (QRgb pixel(intx, inty)) and decide how to construct 4 pixel (void setPixel(intx, inty, QRgba)) on new image.

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mcosta
          wrote on last edited by
          #4

          Ok,

          what means "wrong image"? you should understand if there is some issue on your algorithm or in Qt API.

          Are both Mac and Win platforms at 64bit? Are the source image a standard format available in both platforms??

          Once your problem is solved don't forget to:

          • Mark the thread as SOLVED using the Topic Tool menu
          • Vote up the answer(s) that helped you to solve the issue

          You can embed images using (http://imgur.com/) or (http://postimage.org/)

          1 Reply Last reply
          0
          • M Offline
            M Offline
            ma_sadri
            wrote on last edited by
            #5

            I give both of them the same inputimage but they give me different answer.
            There isn't any problem in algorithm I've test this algorithm on matlab too.

            Output image from windows platform (32-bit):
            http://sadri.persiangig.com/image/Qt/B(Windows).png

            Output image from mac Platform(64-bit, it should be somthing like this):
            http://sadri.persiangig.com/image/Qt/B(mac).png

            source image is in png format.

            1 Reply Last reply
            0
            • M Offline
              M Offline
              mcosta
              wrote on last edited by
              #6

              Are the Mac version correct??

              Have you tried to load and save the image (without data manipulation) in both platform??

              Once your problem is solved don't forget to:

              • Mark the thread as SOLVED using the Topic Tool menu
              • Vote up the answer(s) that helped you to solve the issue

              You can embed images using (http://imgur.com/) or (http://postimage.org/)

              1 Reply Last reply
              0
              • M Offline
                M Offline
                ma_sadri
                wrote on last edited by
                #7

                The Mac version is correct and give me the true image.

                yes there isn't any problem in loading and saving image on both platform.

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  mcosta
                  wrote on last edited by
                  #8

                  In your code at line 14 you use a '|' instead of '||'; it's a typo or not?

                  You should print the results of if condition in order to investigate the source of error

                  Once your problem is solved don't forget to:

                  • Mark the thread as SOLVED using the Topic Tool menu
                  • Vote up the answer(s) that helped you to solve the issue

                  You can embed images using (http://imgur.com/) or (http://postimage.org/)

                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    ma_sadri
                    wrote on last edited by
                    #9

                    Thanks for your great advise mcosta.

                    The problem was solved.

                    The problem is completely related to my platforms (mac 64-bit and win 32-bit), I wrote a function that generate random numbers between 1 and N using qrand() like this:
                    @
                    int random (int a){
                    double rndgen;
                    int rand;
                    rndgen = qrand();
                    rndgen/=(0x7fffffff);
                    rndgen*=a;
                    rndgen+=1;
                    rand=rndgen;
                    return rand;
                    }
                    @

                    And after that i decided how to manipulate data, in my mac it works great but in The Windows random function always return 1 because of RAND_MAX definition, RAND_MAX in 32-bit platforms is equal to 0x7fff but in 64-bit platforms is equal to 0x7fffffff.

                    I've changed above code to this:
                    @
                    int random (int a){
                    double rndgen;
                    int rand;
                    rndgen = qrand();
                    rndgen/=(RAND_MAX);
                    rndgen*=a;
                    rndgen+=1;
                    rand=rndgen;
                    return rand;
                    }
                    @

                    So the problem get solved :-)
                    There isn't any problem with QImage :-)

                    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