1

I am using qt for developing a simple drawing application.

I have a qImage and filled it as trasparent.

QImage *m_markerImg = new QImage(400,320, QImage::Format_ARGB32_Premultiplied); m_markerImg -> fill( Qt::transparent );

I have created a custom graphics scene by inheriting it from qgraphicsscene & drawing a line on this image in the mousemove event of graphics scene as:

QPointF plotPoint = mouseEvent->scenePos(); m_painter.drawLine(m_initPoint,plotPoint); m_initPoint=plotPoint;

where m_initPoint is being assigned in mouse press event. Everything is working fine and i am able to draw lines over this image. Now i want to store the pixels covered by this line at runtime i.e. during line draw. Although i can store the points on which i am drawing i.e. m_initPoint & plotPoint but in case of penwidth is set to more than 1 , then i will get only a single line pixel while i need whole of the pixels covered by the width of this line.

How can i get that?

1 Answers1

0

You need to:

  1. Convert the line to a path,
  2. Stroke the path using QPainterPathStroker (see also this example),
  3. Get the stroked path as a polygon,
  4. Scan (iterate) the pixels of the polygon - see this question for a complete example.
Community
  • 1
  • 1
Kuba hasn't forgotten Monica
  • 95,931
  • 16
  • 151
  • 313
  • Sorry Kuba Ober, but i don't know how to stroke the line. Can you please provide some more info about it? – Shubham Saini Aug 02 '16 at 10:06
  • @ShubhamSaini I've linked relevant documentation/examples. – Kuba hasn't forgotten Monica Aug 02 '16 at 13:16
  • Thanks for looking into the problem, i'll be trying your solution. For now i've solved it by iterating the nearby pixels in vicinity. i.e. i am running loops on the pixels in the vicinity, checking their color and if they have the same color as i applied on them, i am appending them into QList. It is solving my problem. – Shubham Saini Aug 03 '16 at 05:13