【发布时间】:2016-12-26 08:08:45
【问题描述】:
在我的 c# windows 应用程序中,我使用下面的代码成功地将 panel1 捕获为图像(bmp、jpg、png)
int x1 = SystemInformation.WorkingArea.X;
int y1 = SystemInformation.WorkingArea.Y;
int width1 = panel1.Width;
int height1 = panel1.Height;
Rectangle bounds1 = new Rectangle(x1, y1, width1, height1);
Bitmap img1 = new Bitmap(width1, height1);
panel1.DrawToBitmap(img1, bounds1);
我在我的 asp 网站中使用此代码将 asp 面板捕获为图像。但是SystemInformation 和DrawToBitmap 在网络项目中不起作用。谁能给我一个想法,如何捕获具有实际宽度和高度的 asp 面板。
我的完整 Windows 应用程序按钮代码如下
private void savetypebtn_Click(object sender, EventArgs e)
{
try
{
int x1 = SystemInformation.WorkingArea.X;
int y1 = SystemInformation.WorkingArea.Y;
int width1 = panel1.Width;
int height1 = panel1.Height;
Rectangle bounds1 = new Rectangle(x1, y1, width1, height1);
Bitmap img1 = new Bitmap(width1, height1);
panel1.DrawToBitmap(img1, bounds1);
string saved_file = "";
savedialog.InitialDirectory = "D:";
savedialog.Title = "Save Quotation";
savedialog.FileName = "";
savedialog.Filter = "Jpg image|*.jpg|Bitmap image|*.bmp|png image|*.png";
if (savedialog.ShowDialog() != DialogResult.Cancel)
{
saved_file = savedialog.FileName;
img1.Save(saved_file, System.Drawing.Imaging.ImageFormat.Bmp);
}
}
catch (Exception ex)
{
errorlbl.Visible=True;
errorlbl.Text = ex.Message;
}
【问题讨论】:
-
.net 4.0 后不支持DrawToBitmap