在asp.net中将面板另存为图像

在asp.net中将面板另存为图像,asp.net,image,export,drawtobitmap,Asp.net,Image,Export,Drawtobitmap,我在asp.net中有一个面板,其中包含许多图像。我的问题是如何将面板中的所有图像保存为一个图像 是否可以在asp.net中使用drawToBitmap?否,在asp.net面板控件中没有drawToBitmap方法。不用说,您不能在ASP.NET项目中引用Windows窗体程序集来实现这一点 最好的方法是将所有这些图像合并成一个。下面是一个示例c#代码 public static System.Drawing.Bitmap组合(字符串[]文件) { //将所有图像读入内存 列表图像=新列表()

我在asp.net中有一个面板,其中包含许多图像。我的问题是如何将面板中的所有图像保存为一个图像


是否可以在asp.net中使用drawToBitmap?

否,在
asp.net
面板控件中没有
drawToBitmap
方法。不用说,您不能在ASP.NET项目中引用Windows窗体程序集来实现这一点

最好的方法是将所有这些图像合并成一个。下面是一个示例c#代码

public static System.Drawing.Bitmap组合(字符串[]文件)
{
//将所有图像读入内存
列表图像=新列表();
System.Drawing.Bitmap finalImage=null;
尝试
{
整数宽度=0;
整数高度=0;
foreach(文件中的字符串图像)
{
//从文件创建位图并将其添加到列表中
System.Drawing.Bitmap Bitmap=新的System.Drawing.Bitmap(图像);
//更新最终位图的大小
宽度+=位图宽度;
高度=位图。高度>高度?位图。高度:高度;
添加(位图);
}
//创建位图以保存组合图像
finalImage=新系统.绘图.位图(宽度,高度);
返回最终授权;
}
捕获(例外情况除外)
{
if(finalImage!=null)
finalImage.Dispose();
掷骰子;
}
最后
{
//清理内存
foreach(图像中的System.Drawing.Bitmap图像)
{
image.Dispose();
}
}
}

您可以使用WebBrowser控件的WebBrowser.DrawToBitmap方法在位图上渲染结果

请参见此链接,其中包含一个返回网页位图表示形式的示例:


但是如果我创建的是拖放式图像,所以有不同的位置,该怎么办?您可以随时收集图像名称和位置,然后将其发送到服务器进行处理
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();
    }
  }
}