इस ओपी के प्रश्न के लिए एक सीधा जवाब नहीं है, लेकिन यह एक अक्सर अनदेखी उपकरण है कि आप में चीजों के पास जाने की अनुमति दे सकते है एक अलग तरीका, यह जरूरी साबित करना चाहिए।
अक्सर यह कहा जाता है कि ग्राफिक्स ऑब्जेक्ट की सामग्री को प्राप्त करना संभव नहीं है। यह बिल्कुल भी सच नहीं है। सही दृष्टिकोण के साथ आप एचडीसी और बिटब्लैट का उपयोग कर कैनवास पर डेटा तक पहुंच सकते हैं। सी #:
enum TernaryRasterOperations : uint
{
/// <summary>dest = source</summary>
SRCCOPY = 0x00CC0020,
/// <summary>dest = source OR dest</summary>
SRCPAINT = 0x00EE0086,
/// <summary>dest = source AND dest</summary>
SRCAND = 0x008800C6,
/// <summary>dest = source XOR dest</summary>
SRCINVERT = 0x00660046,
/// <summary>dest = source AND (NOT dest)</summary>
SRCERASE = 0x00440328,
/// <summary>dest = (NOT source)</summary>
NOTSRCCOPY = 0x00330008,
/// <summary>dest = (NOT src) AND (NOT dest)</summary>
NOTSRCERASE = 0x001100A6,
/// <summary>dest = (source AND pattern)</summary>
MERGECOPY = 0x00C000CA,
/// <summary>dest = (NOT source) OR dest</summary>
MERGEPAINT = 0x00BB0226,
/// <summary>dest = pattern</summary>
PATCOPY = 0x00F00021,
/// <summary>dest = DPSnoo</summary>
PATPAINT = 0x00FB0A09,
/// <summary>dest = pattern XOR dest</summary>
PATINVERT = 0x005A0049,
/// <summary>dest = (NOT dest)</summary>
DSTINVERT = 0x00550009,
/// <summary>dest = BLACK</summary>
BLACKNESS = 0x00000042,
/// <summary>dest = WHITE</summary>
WHITENESS = 0x00FF0062,
/// <summary>
/// Capture window as seen on screen. This includes layered windows
/// such as WPF windows with AllowsTransparency="true"
/// </summary>
CAPTUREBLT = 0x40000000
}
[DllImport("gdi32.dll", EntryPoint = "BitBlt", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool BitBlt([In] IntPtr hdc, int nXDest, int nYDest, int nWidth, int nHeight, [In] IntPtr hdcSrc, int nXSrc, int nYSrc, TernaryRasterOperations dwRop);
public static Bitmap CopyGraphicsContent(Graphics source, Rectangle rect)
{
Bitmap bmp = new Bitmap(rect.Width, rect.Height);
using (Graphics dest = Graphics.FromImage(bmp))
{
IntPtr hdcSource = source.GetHdc();
IntPtr hdcDest = dest.GetHdc();
BitBlt(hdcDest, 0, 0, rect.Width, rect.Height, hdcSource, rect.X, rect.Y, TernaryRasterOperations.SRCCOPY);
source.ReleaseHdc(hdcSource);
dest.ReleaseHdc(hdcDest);
}
return bmp;
}
का उपयोग करके ऐसा करने का एक तरीका यहां दिया गया है क्या यह प्रश्न का उत्तर देता है? कृपया बताएं कि यह – CocoNess
प्रश्न का उत्तर कैसे देता है हर कोई कहता है कि ग्राफिक्स ऑब्जेक्ट सामग्री की प्रतिलिपि बनाना संभव नहीं है। यह बिल्कुल भी सच नहीं है। आप एचडीसी और बिटब्लैट का उपयोग कर कैनवास पर डेटा तक पहुंच सकते हैं। यहां सी # का उपयोग करके इसे कैसे किया जाए। – user1830791
यही वह है जो मैं खोज रहा था जब मेरी खोज ने ओपी के सवाल को लाया, कई अन्य लोगों के बीच :) –