【发布时间】:2015-10-28 17:55:55
【问题描述】:
以下是将面板信息更改为位图的代码。 位图首先由我的面板信息生成,然后保存为图像文件。 我确认宽度、高度和边界代表了我的面板给出的正确信息。 我目前不确定为什么我的结果 bmp/jpeg 文件与面板上的图像不同。
//位图保存功能
Bitmap bmp = new Bitmap(panel1.ClientSize.Width, panel1.ClientSize.Height);
Debug.WriteLine("bounds: " + panel1.ClientRectangle);
this.panel1.DrawToBitmap(bmp, panel1.ClientRectangle);
bmp.Save(@"C:\Documents and Settings\Flaw\Desktop\Test.bmp", ImageFormat.Bmp);
//绘图函数
System.Drawing.Graphics graphicsObj;
graphicsObj = this.panel1.CreateGraphics();
Pen myPen = new Pen(System.Drawing.Color.Black, 5);
graphicsObj.Clear(Color.White);
//graphicsObj.DrawLine(myPen, 50, 50, 100, 100);
if (bCircle)
{
graphicsObj.DrawEllipse(myPen, x, y, 100, 100);
}
else if (bSquare)
{
graphicsObj.DrawRectangle(myPen, x, y, 100, 100);
}
我保存位图得到的结果。
panel1 上的图像(从我的窗口窗体中裁剪)
【问题讨论】:
标签: c#