[Solved] QImage works different on windows.



  • 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.



  • Hi,

    posting your code probably you can get more help



  • [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.



  • 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??



  • 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.



  • Are the Mac version correct??

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



  • 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.



  • 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



  • 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 :-)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.