开发者

What is the best way to copy / clone brushes?

开发者 https://www.devze.com 2023-02-19 20:57 出处:网络
Before drawing a shape on a canvas I have a preview that displays how the shape will look.I can adjust the opacity and then draw the shape.I may then wish to draw a second shape with a different opaci

Before drawing a shape on a canvas I have a preview that displays how the shape will look. I can adjust the opacity and then draw the shape. I may then wish to draw a second shape with a different opacity. My problem is that altering the opacity of the preview also alters the opacity of the shape that I have already drawn.

This has led me to believe that I need to create a copy of the brush used for the preview each time before drawing the shape.

There are various different brushes and for example, the gradient brushes require making a copy of the not just the gradient stop collection, but a new gradient stop for each gradien开发者_JAVA百科t stop in the to-be-copied collection.

Am I down the right track here or should I be doing something else? Should I be copying or cloning? Would an extension method be the best way to go? Thoughts please.


What you need is cloning, it would be easy in wpf with XamlWriter/Reader, unfortunately you cannot do it in Silverlight. An extension method on Brush that makes a deep copy would work fine in your case though. You will have to handle the different brush type separately but it should not be an issue as there aren't that many.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号