Unsolved line to pixel Scene
-
Hello everyone.
First of all thanks a lot for helping me and reading this post.i have some lines in scene. I have their coordinates in pixels (XStart YStart XEnd YEnd).
Now I would like to transform this line to a QImage con my resolution (for example 0.1 meter/pixel)
Is there any function or class that it can help me?Thanks a lot!
-
Hi
Its very unclear what you mean. (for me)say we have line from 100,100 to 400,400
Now you want to paint the same line on a QImage?
The QImage also use pixels so you can just draw it.
-
@mrjj hi again friend. Thanks for replying.
Yes, i have the coordinates in pixels.
And I want to draw the line in an image. Which function have I to use? -
Hey,
you can try the drawLine function from the QPainter:
QImage image = ...; QPainter painter(&image); painter.drawLine(x1, y1, x2, y2); // If the painter cant draw on an image directly, try to draw on the pixmap of the image: QPixmap pix = QPixmap::fromImage(image); QPainter painter(&pix); painter.drawLine(x1, y1, x2, y2); image = pixmap.toImage();
-
@onek24 Thanks my friend!
i can use that, but how can I do for using a resolution. For example 0.01 meter/pixel for drawing the line?!
-
@onek24 said:
Hey,
you can try the drawLine function from the QPainter:
QImage image = ...; QPainter painter(&image); painter.drawLine(x1, y1, x2, y2); // If the painter cant draw on an image directly, try to draw on the pixmap of the image: QPixmap pix = QPixmap::fromImage(image); QPainter painter(&pix); painter.drawLine(x1, y1, x2, y2); image = pixmap.toImage();
@AlvaroS said:
@onek24 Thanks my friend!
i can use that, but how can I do for using a resolution. For example 0.01 meter/pixel for drawing the line?!
i have just used this:
QPen line_res; line_res.setColor(Qt::black); line_res.setWidthF(resolution); painter.setPen(line_res);
But width function is not the resolution in m/px...
-
For example in the first image here: http://doc.qt.io/qt-4.8/coordsys.html
how can I set the size of each square(the size in meter of each pixel)?
@mrjj @onek24 -
If you say 0.01 meter per pixel, then a 2.5 meter line would need 2.5 / 0.01 = 250 pixel
-
@jsulm Yes! But I do not how to set this resolution of each pixel (each square)
-
You cannot as far as I know. It is something related to your application. QPainter does not know any thing about meter it uses pixels, so it is your job to translate meters to pixels.
-
Each "square" in the qt matrix is 1, Its the basic unit. Usually you cant work directly with pixel-metric size combinations. The size of an actual pixel is defined by your display, lets say your display has a DPI(Dots per inch) of 100, that means it has 100 dots on 1 inch lench, which is approximately 40 pixels per centimeter. So if you want to draw a line which has a physical length of, lets say 1 meter, then you have to take your DPI, make it dots per centimeter by division of roughly 2,54, and then multiply it by 100 to make it dots per meter. That would be the length of your line. You can do these calculation for width or whatever. Afaik if the Scene isn't scaled, 1 pixel or square on the qt scene is 1 physical pixel. So drawing would be enough, as long as you dont scale the qt scene.