const int SRCCOPY = 0xCC0020; [DllImport("gdi32.dll")] static extern int BitBlt(IntPtr hdc, int x, int y, int cx, int cy, IntPtr hdcSrc, int x1, int y1, int rop); Image PrintClientRectangleToImage() { var bmp = new Bitmap(ClientSize.Width, ClientSize.Height); using (var bmpGraphics = Graphics.FromImage(bmp)) { var bmpDC = bmpGraphics.GetHdc(); using (Graphics formGraphics = Graphics.FromHwnd(this.Handle)) { var formDC = formGraphics.GetHdc(); BitBlt(bmpDC, 0, 0, ClientSize.Width, ClientSize.Height, formDC, 0, 0, SRCCOPY); formGraphics.ReleaseHdc(formDC); } bmpGraphics.ReleaseHdc(bmpDC); } return bmp; } ///使用 Bitmap bitmap = PrintClientRectangleToImage(this.panel1); c# - How to use Control.DrawToBitmap to render a Form into a Bitmap without its decorations (titlebar, border)? - Stack Overflow
替换 DrawToBitmap 方案 支持自定义(Graphics)边框
最新推荐文章于 2023-05-12 00:03:10 发布