GDI+嵌套图形对象

发布于 2024-12-09 10:06:06 字数 692 浏览 1 评论 0原文

使用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:

enter image description here

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

彡翼 2024-12-16 10:06:06

假设两个矢量上下文在绘制时可以分开,您可以使用 System.Drawing.Imaging.Metafile 来捕获矢量操作,然后将它们组合到更大的上下文中。像这样:

using (Graphics gRef = this.CreateGraphics())  
{  
    IntPtr hdc = gRef.GetHdc();  
    using (System.Drawing.Imaging.Metafile mf = 
           new System.Drawing.Imaging.Metafile(hdc, 
                System.Drawing.Imaging.EmfType.EmfPlusDual))  
        {  
          gRef.ReleaseHdc();  

          using (Graphics redG = Graphics.FromImage(mf))  
          {  
            redG.SetClip(new RectangleF(...));

            // .. draw on redG 
          }  
          // repeat for greenG

          // .. save and or combine as desired

        }  
    } 

}

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:

using (Graphics gRef = this.CreateGraphics())  
{  
    IntPtr hdc = gRef.GetHdc();  
    using (System.Drawing.Imaging.Metafile mf = 
           new System.Drawing.Imaging.Metafile(hdc, 
                System.Drawing.Imaging.EmfType.EmfPlusDual))  
        {  
          gRef.ReleaseHdc();  

          using (Graphics redG = Graphics.FromImage(mf))  
          {  
            redG.SetClip(new RectangleF(...));

            // .. draw on redG 
          }  
          // repeat for greenG

          // .. save and or combine as desired

        }  
    } 

}
且行且努力 2024-12-16 10:06:06

另一种方法是研究增强型图元文件格式 (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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文