I have a panel in asp.net that contains many images. My problem is how to save the all image in the panel as 1 image.
Is it possible to use drawToBitmap in asp.net?
I have a panel in asp.net that contains many images. My problem is how to save the all image in the panel as 1 image.
Is it possible to use drawToBitmap in asp.net?
No, there's no DrawToBitmap
method in the ASP.NET
Panel control. Needless, to say that you can not reference the Windows Forms assembly in your ASP.NET project to achieve this.
The best shot you've got is to combine all of these images into one. Here's a sample c# code...
public static System.Drawing.Bitmap Combine(string[] files)
{
//read all images into memory
List<System.Drawing.Bitmap> images = new List<System.Drawing.Bitmap>();
System.Drawing.Bitmap finalImage = null;
try
{
int width = 0;
int height = 0;
foreach (string image in files)
{
//create a Bitmap from the file and add it to the list
System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(image);
//update the size of the final bitmap
width += bitmap.Width;
height = bitmap.Height > height ? bitmap.Height : height;
images.Add(bitmap);
}
//create a bitmap to hold the combined image
finalImage = new System.Drawing.Bitmap(width, height);
return finalImage;
}
catch(Exception ex)
{
if (finalImage != null)
finalImage.Dispose();
throw ex;
}
finally
{
//clean up memory
foreach (System.Drawing.Bitmap image in images)
{
image.Dispose();
}
}
}
You could render the result on a bitmap using the WebBrowser.DrawToBitmap method of the WebBrowser control.
See this link with an example that returns a Bitmap representation of a webpage:
http://pietschsoft.com/post/2008/07/c-generate-webpage-thumbmail-screenshot-image