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);
    }

posted @ 2010-04-16 14:52  陌香  阅读(306)  评论(0编辑  收藏  举报