Paint. editor



  • I want to make a pixel editor, but i don't know how start, any tips?

    Thanks in advance.



  • Focus around QPainter and QPixmap. A brush can be represented by a monochrome 8 bit pixmap you can colorize in the desired color, then using QPainter you can imprint the brush pixmap onto another pixmap that represents your canvas.

    Keep in mind that QBrush won't provide the needed behavior.

    If this is your brush stencil:
    !http://i41.tinypic.com/34dr5nt.png(stenci)!

    using QBrush to fill a stroke will produce this:
    !http://i41.tinypic.com/21mde8j.png(qbrush)!

    it will fill the stroke in a patterned style instead of what an actual stroke with the stencil should look like:
    !http://i39.tinypic.com/2642m2e.png(brush)!

    Typically, you'd want to store 2 coordinates while drawing, the previous and current position of the cursor. Then you create a QLine between the two QPoints and draw the brush pixmap along that line based on how much your brush spacing is. This is the approach needed to solve the issue, presented by Qt's slow input event polling, which would create arbitrary single points along the path of drawing instead of a consistent line.

    Of course if you want only single pixel the task will be much easier. Bud going for the "brush" approach will allow you to draw with any kind of brush, not only pixel. You can also create brushes that automatically rotate to follow the direction of drawing, brush dynamics in regard to size, opacity, color, noise and so on.

    On how to colorize your brush, I already show a well commented step by step example "here":http://qt-project.org/forums/viewthread/18048

    There is also a sketch example shipping with Qt, but it is very limited in providing the ability to use different brush stencils.



  • Thank you!!! Thank you!!! Thank you!!!! utcenter ;) This and your other posts were exactly the information I have been looking for, Please post more on the subject of this topic when you can. It would be much appreciated.

    Thank you soooo much!!!!


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.