In my c# windows application i successfully captured panel1 as image (bmp, jpg, png) using below code
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);
I used this code in my asp website to capture asp panel as image. But SystemInformation
and DrawToBitmap
not working in web project. Can anyone give me an idea that how to capture asp panel with actual width and height.
my full windows app button code is given below
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;
}