How expensive is it to create gdi brushes and pens? Should I create them on an add needed basis and wrap them in a using so they are disposed quickly, or should I create a static class similar to System.Drawing.Brushes class?
To use a brush pen, hold it close to the nib to give you more control over your strokes. Try to keep your wrist and fingers still and move your arm to direct the pen. Use upstrokes and apply light pressure to create thin lines. For thick lines, use downstrokes and apply heavy pressure.
They're also great if you're into crafts; watercolor brush pens allow you to create unique styles like dainty florals and hand lettering that can be used to make cards, invitations and art prints. On top of that, they can be used for adult coloring books, too.
IMO, they're efficient enough that you should usually not create long-lived instances that are used over several method calls, but inefficient enough that you should create each one only once within a particular method, instead of creating a new one each time you need to draw something.
In other words, don't store a custom brush in your class that you use to paint your text on every OnPaint
call, but also don't create a new brush for every line of text you draw within that OnPaint call, either.
I've encountered exceptions when trying to custom draw images in a web application under load with a static brush.
I don't know the technical reasons, but I think Brushes and Pens are not thread safe, so I would create them as needed in a thread-safe manner and dispose of them within that scope, probably with a using.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With