QImage editing using inches
-
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!
-
@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?
-
@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 -
@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?
-
@Christian-Ehrlicher DPI is known. Output device is the same image saved in TIFF format. Let's admit DPI is 300.
-
Then you know how much pixels are 1dpi and can calculate the rest on your own.
-
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.