1
votes

Any suggestions on how to replicate the HatchStyle from GDI in Direct2D ?

https://msdn.microsoft.com/en-us/library/windows/desktop/dd144966%28v=vs.85%29.aspx

What to consider :

1) The color of the lines must be the same as the color of the Brush, like in GDI.
2) Must be performant

So far, here are my potential solutions :
1) Use a ID2D1BitmapBrush on which I draw the lines with the specified color.
That means I need to recreate the brush every time the colors changes or when the HatchStyle changes. Draw the BitmapBrush on the specified area and take advantage of the BitmapBrush ExtendMode WRAP to repeat the pattern in X and Y.

2) Draw all the lines one by one over the area with the specified color.

1
What do you mean by "must be performant"? - Emond Erno
@erno-de-weerd I don't want the drawing of the HatchStyle to be costly in time. I have no specific measures, but I just want it to be fast. - Sim

1 Answers

0
votes

Here's another choice: create two masks, one for the primary color and the other for the secondary color (which should just be the inverse of the first mask). Then call FillOpacityMask twice. The first call will use the first mask + a solid color brush for the primary color, and the second call is second mask + solid color brush for the secondary color.