我在 asp.net 中有一个面板,其中包含许多图像。我的问题是如何将面板中的所有图像保存为 1 张图像。
是否可以在 asp.net 中使用 drawToBitmap?
我在 asp.net 中有一个面板,其中包含许多图像。我的问题是如何将面板中的所有图像保存为 1 张图像。
是否可以在 asp.net 中使用 drawToBitmap?
不, Panel 控件中没有DrawToBitmap
方法。ASP.NET
不用说,您不能在您的 ASP.NET 项目中引用 Windows 窗体程序集来实现这一点。
您获得的最佳照片是将所有这些图像组合成一张。这是一个示例 C# 代码...
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();
}
}
}
您可以使用 WebBrowser 控件的 WebBrowser.DrawToBitmap 方法在位图上呈现结果。
请参阅此链接以及返回网页的位图表示的示例:
http://pietschsoft.com/post/2008/07/c-generate-webpage-thumbmail-screenshot-image