如何复制一个图形对象到另一个 [英] How to copy one Graphics Object into another
问题描述
我试图复制一个图形的内容,对象到另一个,但唯一被我已经能够找到基于使用 GDI32.DLL
,这是我宁愿避免可能的话使用。
有谁知道如何/如果这是可能使用管理code?我不介意,如果答案是C#或VB.Net。
下面是我目前有:
私人小组CopyGraphics()
昏暗srcPic作为图形= pnl.CreateGraphics
昏暗srcBmp作为新位图(pnl.Width,pnl.Height,srcPic)
昏暗SRCMEM作为图形= Graphics.FromImage(srcBmp)
昏暗hdc1分区作为IntPtr的= srcPic.GetHdc
昏暗HDC2作为IntPtr的= srcMem.GetHdc
的BitBlt(HDC2,0,0,pnl.Width,pnl.Height,hdc1分区,0,0,13369376)
pnlDraw.BackgroundImage = srcBmp
清理code省略...
结束小组
从严格意义上讲,这是不可能的对象在任何地方使用任何方法复制的图形的内容,因为一个图形对象不包含任何内容。
为什么不使用DrawToBitmap方法来绘制位图上的控制?
昏暗srcBmp作为新位图(pnl.Width,pnl.Height)
昏暗的剪辑作为新的矩形(新点(0,0),pnl.Size)
pnl.DrawToBitmap(srcBmp,剪辑)
I am trying to copy the contents of one graphics object to another, but the only was I have been able to find is based on using GDI32.DLL
, which i would rather avoid using if possible.
Does anyone know how/if this is possible using managed code? I don't mind if answers are in C# or VB.Net.
Here is what I currently have:
Private Sub CopyGraphics()
Dim srcPic As Graphics = pnl.CreateGraphics
Dim srcBmp As New Bitmap(pnl.Width, pnl.Height, srcPic)
Dim srcMem As Graphics = Graphics.FromImage(srcBmp)
Dim HDC1 As IntPtr = srcPic.GetHdc
Dim HDC2 As IntPtr = srcMem.GetHdc
BitBlt(HDC2, 0, 0, pnl.Width, pnl.Height, HDC1, 0, 0, 13369376)
pnlDraw.BackgroundImage = srcBmp
'Clean Up code omitted...
End Sub
Strictly speaking, it's not possible to copy the contents of a Graphics object anywhere using any method, because a Graphics object doesn't contain anything.
Why don't use the DrawToBitmap method to draw the control on the bitmap?
Dim srcBmp As New Bitmap(pnl.Width, pnl.Height)
Dim clip As New Rectangle(New Point(0, 0), pnl.Size)
pnl.DrawToBitmap(srcBmp, clip)
这篇关于如何复制一个图形对象到另一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!