SaveGraphics

    class SaveGraphics
    {
        //使用方法
        //Graphics g = chartControl1.CreateGraphics();
        //FromGraphics(g, chartControl1.Width, chartControl1.Height).Save("D:/a.jpg");
        public static Bitmap FromGraphics(Graphics g, int w, int h)
        {
            const int SRCCOPY = 0xcc0020;
            Bitmap b = new Bitmap(w, h);
            Graphics gd = Graphics.FromImage(b);

            BitBlt(new HandleRef(null, gd.GetHdc()), 0, 0, w, h,
             new HandleRef(null, g.GetHdc()), 0, 0, SRCCOPY);
            gd.ReleaseHdc(); g.ReleaseHdc();
            return b;
        }
        [DllImport("gdi32.dll", CharSet = CharSet.Auto, SetLastError = true, ExactSpelling = true)]
        public static extern int BitBlt(HandleRef hDesDC, int x, int y, int w, int h, HandleRef hSrcDC, int xSrc, int ySrc, int dwRop);
    }

原文地址:https://www.cnblogs.com/_zjl/p/1713601.html