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. Printing a QImage has color distortion
Forum Updated to NodeBB v4.3 + New Features

Printing a QImage has color distortion

Scheduled Pinned Locked Moved General and Desktop
17 Posts 2 Posters 5.9k 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.
  • B Offline
    B Offline
    BasiC
    wrote on last edited by BasiC
    #6

    Hi,

    I've been looking all over for some documentation about asking the printer to perform the conversion, but it didn't look promising with my printer.

    About pixel manipulation, you mean that I would need to modify the data buffer itself or I could, in some way, fool Qt into thinking it is RGBA if I set it right ? Do you have some examples ?

    I'll take a look into ImageMagick...

    Thanks,

    BasiC

    1 Reply Last reply
    1
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #7

      Hi
      Only something like this
      http://stackoverflow.com/questions/27949569/convert-a-qimage-to-grayscale
      https://www.programmingalgorithms.com/algorithm/rgb-to-cmyk?lang=C%2B%2B
      QColor also has CMYK support.

      1 Reply Last reply
      2
      • B Offline
        B Offline
        BasiC
        wrote on last edited by
        #8

        Hello again,

        I did figure that QColor supported CMYK, but I am unsure as to how I should put it all together back in the image. Once I get a QColor object from the QColor::toCMYK() call, the only way I can replace the pixel inside the QImage is through QColor::rgba, which returns actual RGBA values. However, I now remember that I had not opened the file explicitly in RGBA format at the time. I will attempt this again and see what I can come up with.

        I'll keep you updated.

        Thanks,

        BasiC

        1 Reply Last reply
        1
        • B Offline
          B Offline
          BasiC
          wrote on last edited by
          #9

          Hi back,

          I tried something like this :

          studentPicture.convertToFormat(QImage::Format_RGBA8888);
          
              for(int j = 0; j < studentPicture.height(); j++)
              {
                  for(int i = 0; i < studentPicture.width(); i++)
                  {
                      int c = 0, m = 0, y = 0, k = 0;
                      QColor oldColor = studentPicture.pixel(i, j);
                      oldColor = oldColor.toCmyk();
                      oldColor.getCmyk(&c, &m, &y, &k);
                      QColor newColor(c, m , y, k);
                      studentPicture.setPixel(i, j, newColor.rgba());
                  }
              }
          

          However, the result doesn't look promising at all... Do you have any more pointer for me ?

          Thanks,

          BasiC

          1 Reply Last reply
          0
          • mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #10

            Hi wb
            Does look like I would expect.
            But you still have massive color
            I wonder if .setPixel(i, j, newColor.rgba() << will that convert back to RGB? );

            http://doc.qt.io/qt-5/qimage.html#setPixelColor-1
            It seems to accept a QColor directly so maybe it can get rid of the .rgb() ?

            Sadly I have not tested this with Cmyk - only greyscale and other manipulations so
            im not sure why its not working.

            Also, i would install ImageMagick and make a Cmyk version and print it. just be sure it will work and
            you have a Cmyk version to compare with.
            Since Scribus can print nicely I assume 99.9% its due to Qt sending image as RGB.

            1 Reply Last reply
            0
            • B Offline
              B Offline
              BasiC
              wrote on last edited by
              #11

              Good morning,

              Removing .rgba() doesn't compile. I need to head to work, but I'll try printing with a CMYK converted image too as soon as I can.

              Thanks,

              BasiC

              1 Reply Last reply
              0
              • B Offline
                B Offline
                BasiC
                wrote on last edited by
                #12

                Hi,

                I tried printing the CMYK output and it still looked bad, but I'm guessing Qt might be converting it to rgb when it loads it ?

                Thanks

                1 Reply Last reply
                0
                • mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #13

                  @BasiC
                  Yes, i would assume it does.
                  Im not sure how to bypass that.

                  After removing rgb() did you use
                  http://doc.qt.io/qt-5/qimage.html#setPixelColor-1
                  Note its not setPixel, but set PixelColor and it accpet a "pure" color?

                  1 Reply Last reply
                  0
                  • B Offline
                    B Offline
                    BasiC
                    wrote on last edited by
                    #14

                    @mrjj
                    You caught me off guard with the added Color in method name. I'll try it out as soon as I get a minute.

                    1 Reply Last reply
                    0
                    • B Offline
                      B Offline
                      BasiC
                      wrote on last edited by BasiC
                      #15

                      Tried the code. I only exported to PDF for testing purposes and I believe it wouldn't print properly...

                      alt text

                      By the way, this looks a little like when I was using .rgba().

                      mrjjM 1 Reply Last reply
                      0
                      • B BasiC

                        Tried the code. I only exported to PDF for testing purposes and I believe it wouldn't print properly...

                        alt text

                        By the way, this looks a little like when I was using .rgba().

                        mrjjM Offline
                        mrjjM Offline
                        mrjj
                        Lifetime Qt Champion
                        wrote on last edited by mrjj
                        #16

                        @BasiC
                        Well its pretty hard to look at CMYK images on RGB monitor and know if they be all right :)
                        PDF might convert to RGB as in adobe its default . Dont know if Qt export is.
                        You could ask Adobe Reader to save as cmyk to be sure. ( if you have it)

                        Maybe its not possible to do in Qt directly as setPixelColor does accept Color CMYK version
                        so it should have worked. Also the images you load are JPGS ? (png not good for cmyk i read)

                        I think it still get convert to RGB or something. that all other pixel manipulation works.
                        Maybe its needed to construct raw buffer and handle all loading and saving by own code.

                        Also if you did install imagemagick
                        try
                        convert image-rgb.jpg -colorspace CMYK image-cmyk.jpg
                        and print from windows

                        1 Reply Last reply
                        0
                        • B Offline
                          B Offline
                          BasiC
                          wrote on last edited by
                          #17

                          Thanks for the reply. I'm in a little rush currently. Hopefully I can test your pointers out pretty soon.

                          1 Reply Last reply
                          1

                          • Login

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • Users
                          • Groups
                          • Search
                          • Get Qt Extensions
                          • Unsolved