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. QImage editing using inches
QtWS25 Last Chance

QImage editing using inches

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 3 Posters 582 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.
  • O Offline
    O Offline
    Oleg R.
    wrote on last edited by
    #1

    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
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @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 Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      1
      • O Offline
        O Offline
        Oleg R.
        wrote on last edited by
        #3

        @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
        0
        • Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @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 Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          O 1 Reply Last reply
          0
          • Christian EhrlicherC Christian Ehrlicher

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

            O Offline
            O Offline
            Oleg R.
            wrote on last edited by
            #5

            @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
            0
            • Christian EhrlicherC Offline
              Christian EhrlicherC Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #6

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

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              1 Reply Last reply
              0
              • O Oleg R.

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

                W Offline
                W Offline
                wrosecrans
                wrote on last edited by
                #7

                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
                1

                • Login

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