复制/克隆画笔的最佳方法是什么?
在画布上绘制形状之前,我有一个预览,显示形状的外观。我可以调整不透明度,然后绘制形状。然后我可能希望绘制具有不同不透明度的第二个形状。我的问题是,改变预览的不透明度也会改变我已经绘制的形状的不透明度。
这让我相信我需要在每次绘制形状之前创建用于预览的画笔副本。
有各种不同的画笔,例如,渐变画笔不仅需要复制渐变停止点集合,还需要为要复制的集合中的每个渐变停止点创建一个新的渐变停止点。
我走在正确的道路上还是应该做点别的事情?我应该复制还是克隆?扩展方法是最好的方法吗?请思考。
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 gradient 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你需要的是克隆,在 wpf 中使用 XamlWriter/Reader 很容易,不幸的是你不能在 Silverlight 中做到这一点。不过,Brush 上进行深层复制的扩展方法在您的情况下可以很好地工作。您必须单独处理不同的画笔类型,但这应该不是问题,因为没有那么多。
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.