我正在尝试保存,然后在 C# 中打印一个面板。我唯一的问题是它只保存可见区域,当我向下滚动时它会打印出来。
Bitmap bmp = new Bitmap(this.panel.Width, this.panel.Height);
this.panel.DrawToBitmap(bmp, new Rectangle(0, 0, this.panel.Width, this.panel.Height));
bmp.Save("c:\\panel.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
最佳答案
尝试跟随
public void DrawControl(Control control,Bitmap bitmap)
{
control.DrawToBitmap(bitmap,control.Bounds);
foreach (Control childControl in control.Controls)
{
DrawControl(childControl,bitmap);
}
}
public void SaveBitmap()
{
Bitmap bmp = new Bitmap(this.panel1.Width, this.panel.Height);
this.panel.DrawToBitmap(bmp, new Rectangle(0, 0, this.panel.Width, this.panel.Height));
foreach (Control control in panel1.Controls)
{
DrawControl(control, bmp);
}
bmp.Save("d:\\panel.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
}
这是我的结果:
表单截图:
保存的位图:
如您所见,TextBox 在表单上不可见,但存在于保存的位图中
关于c# - 将面板保存为 JPEG,仅保存可见区域 c#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6001576/