GDI+嵌套图形对象
使用System.Drawing.Graphics
,我如何拥有“嵌套图形对象”。 主要目的是有几个剪切区域。
这就是我想做的事情:
整个屏幕是一个 Graphics 对象
红色区域是另一个 Graphics其内部和剪裁的
绿色区域是另一个,剪裁的
Inside Graphics 对象可以是任何东西,不仅是 DrawString
代码应该如下所示:
using (var bmp = new System.Drawing.Bitmap(200, 200))
using (var mainG = System.Drawing.Graphics.FromImage(bmp))
using (var redG = ???)
using (var greenG = ???)
{
redG.SetClip(new RectangleF(...));
greenG.SetClip(new RectangleF(...));
// fill redG and greenG
}
注意:结果应该转到元文件并且是矢量图形,因此创造位图并将它们放置在 mainG 周围不是一个选项。
With System.Drawing.Graphics
, how can I have "nested graphics objects".
The main purpose is to have several clipped regions.
This is somehow the thing I want to do:
The whole screen is a Graphics object
Red area is another Graphics inside it and clipped
Green area is another one, clipped
Inside Graphics objects can be anything NOT only DrawString
The code should look like this:
using (var bmp = new System.Drawing.Bitmap(200, 200))
using (var mainG = System.Drawing.Graphics.FromImage(bmp))
using (var redG = ???)
using (var greenG = ???)
{
redG.SetClip(new RectangleF(...));
greenG.SetClip(new RectangleF(...));
// fill redG and greenG
}
NOTE: the result should go to a meta file and be vector graphic, so creating bitmaps and placing them around the mainG is NOT an option.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
假设两个矢量上下文在绘制时可以分开,您可以使用 System.Drawing.Imaging.Metafile 来捕获矢量操作,然后将它们组合到更大的上下文中。像这样:
Assuming it's okay for the two vector contexts to be seperate while they are drawn into, you can use System.Drawing.Imaging.Metafile to catch the vector operations and then combine them into the bigger context.. Something like this:
另一种方法是研究增强型图元文件格式 (http://msdn.microsoft .com/en-us/library/cc230724.aspx)并尝试手动重现剪切蒙版。
An alternative approach would be to study the Enhanced Metafile format (http://msdn.microsoft.com/en-us/library/cc230724.aspx) and try to reproduce clipping masks manually.