Search code examples
c++windowsgraphicsgdi

Drawing a dot with Windows GDI


I am very familiar with the Windows GDI graphics API and there is a function I have been missing for ages: how to draw a dot ?

By a dot, I mean a small pattern of pixels, say a 3x3 or 5x5 square (possibly with corners omitted), all the same color.

My constrains are that I want to do this efficiently and with as little resources as possible.

  • I could use the SetPixel function as many times as required (25 calls for a 5x5 square).

  • I could probably use the MoveTo/LineTo calls with a thick pen twice on the same coordinates. But I am unsure that this will generate a full dot, and I don't like the idea of creating a dedicated pen.

  • I can also use the Rectangle or Ellipse function, but these ones draw the outline and fill the inside and must be an overkill for such a tiny shape. (Not counting the fact that they require a dedicated pen and a dedicated brush.)

Do you have any insight on what could be an efficient and handy approach ? How would you do that ?


Solution

  • At least as far as I know, none of the available options is really ideal. That given, it seems to me that FillRect is probably the least problematic.

    This requires that you create a brush of the correct color, but at least that's all it requires.