Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

    Unsolved QImage editing using inches

    General and Desktop
    3
    7
    231
    Loading More Posts
    • 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.
    • O
      Oleg R. last edited by

      Hello,

      I have created an image of specific size in pixels, for example 1000x1000 pixels, with resolution of 120DPI. How can I draw on that image setting coordinates in inches or mm? For example to draw a box 1x1 inch?

      Also, what kind of interpolations are supported? I'm looking for bilinear and bicubic.

      Thanks a lot!

      1 Reply Last reply Reply Quote 0
      • Christian Ehrlicher
        Christian Ehrlicher Lifetime Qt Champion last edited by

        @Oleg-R said in QImage editing using inches:

        Also, what kind of interpolations are supported? I'm looking for bilinear and bicubic.

        Qt only supports bilinear by default: https://doc.qt.io/qt-5/qt.html#TransformationMode-enum

        How can I draw on that image setting coordinates in inches or mm?

        Are you aware that this depends on the dpi of your output device which is different for every device? So what dpi has you output device?

        Qt has to stay free or it will die.

        1 Reply Last reply Reply Quote 1
        • O
          Oleg R. last edited by

          @Christian-Ehrlicher said in QImage editing using inches:

          Qt only supports bilinear by default: https://doc.qt.io/qt-5/qt.html#TransformationMode-enum
          Yes, I did not find anything else, any suggestion for the lib to use to get more interpolation modes? I am considering OpenCV lib for now.

          Are you aware that this depends on the dpi of your output device which is different for every device? So what dpi has you output device?

          Yes, I do. My task is to create an image knowing its pixel dimension, resolution (DPI). For example:

          QImage img(imgWidth, imgHeight, QImage::Format_ARGB32);
          

          Now, I need to draw a half-inch line exactly 0.43 inches from the left edge.

          QPainter painter(&img);
          painter.drawRect(0.43, YinInch, 0.5, 10);
          

          I tried setting painter.window, but it gives me some strange transformation:

          painter.setWindow(0, 0, imgWidthMm / 25.4, imgHeightMm / 25.4);
          

          Any ideas, or just leave it and use OpenCV?

          Best regards,
          Oleg Romanenko

          1 Reply Last reply Reply Quote 0
          • Christian Ehrlicher
            Christian Ehrlicher Lifetime Qt Champion last edited by

            @Oleg-R said in QImage editing using inches:

            Now, I need to draw a half-inch line exactly 0.43 inches from the left edge.

            How should this work when you don't know the dpi of your output device?

            Qt has to stay free or it will die.

            O 1 Reply Last reply Reply Quote 0
            • O
              Oleg R. @Christian Ehrlicher last edited by

              @Christian-Ehrlicher DPI is known. Output device is the same image saved in TIFF format. Let's admit DPI is 300.

              W 1 Reply Last reply Reply Quote 0
              • Christian Ehrlicher
                Christian Ehrlicher Lifetime Qt Champion last edited by

                Then you know how much pixels are 1dpi and can calculate the rest on your own.

                Qt has to stay free or it will die.

                1 Reply Last reply Reply Quote 0
                • W
                  wrosecrans @Oleg R. last edited by

                  If it's 120 DPI, then 1 inch will be 120 pixels.

                  pixels = inches * dpi;

                  So, a half inch at 300 dpi is

                  0.5 * 300 = 150 pixels. Just take all your inch measurements, and convert them into pixels for the operations. The math here isn't terribly obscure, just arithmetic. It sounds like you are overthinking it trying to come up with something more complicated.

                  1 Reply Last reply Reply Quote 1
                  • First post
                    Last post