【问题标题】:Converting aspx page to image file将aspx页面转换为图像文件
【发布时间】:2013-10-16 20:23:19
【问题描述】:

添加新属性后,我为记录手册创建了 c# 动态 aspx 页面

http://veneristurkey.com/admin/Brochure.aspx?Admin=PropertiesBrochureA4&id=36

但我想转换我在互联网上搜索的图像文件,但全部使用 webbrowser 和 windows 窗体。我需要在页面加载时显示不是 css 类型的图像文件。 jpg、png 或 tiff 我怎么能做到这一点。我需要看示例代码..

将 aspx 页面保存为图像 2

【问题讨论】:

  • 一个 aspx 做了它需要在服务器上做的事情来返回 html。呈现的 html 是您可以在该链接上看到的内容。我建议您搜索“html to image”而不是“aspx to image”。仅在 google 上就有很多结果。
  • @DeeMac 的建议仍然有效,最简单的方法是让页面呈现为 Html,然后将其转换为图像文件。我不知道有任何内置工具可以直接渲染到图像。您也许可以创建一个页面,该页面调用您希望成为图像的页面,获取 html,然后将其转换为图像并将图像返回给用户或您想要对其进行的任何操作。

标签: c# asp.net html image image-generation


【解决方案1】:

正如我在评论中提到的,您最好的选择是尝试将 HTML 呈现为图像。

这是一个允许您将 html 呈现到图像的库的链接:

http://htmlrenderer.codeplex.com/

这是完全符合您要求的代码:

http://amoghnatu.wordpress.com/2013/05/13/converting-html-text-to-image-using-c/

现在你剩下的就是获取 html,因为我假设你不希望在生成此图像之前将其呈现给浏览器 - 你应该考虑从 aspx 页面上抓取呈现的 html服务器在返回它之前,然后只返回图像。渲染页面:

https://stackoverflow.com/a/647866/1017882

已排序。

【讨论】:

    【解决方案2】:

    如果您不介意使用命令行工具,可以查看wkhtmltopdf。该包包含一个 wkhtmltoimage 组件,可用于将 HTML 转换为图像,使用

    wkhtmltoimage [URL] [Image Path]
    

    Codaxy 还编写了一个wkhtmltopdf c# wrapper,可通过 NuGet 包管理器获得。我不确定是否包含 wkhtmltoimage 组件,但应该很容易弄清楚它们是如何包装 wkhtml 组件的。

    【讨论】:

      【解决方案3】:

      我用截图机 API 解决了我的问题,它们是我的代码..

      public void resimyap() {

              var procad = WS.Satiliklars.Where(v => v.ForSaleID == int.Parse(Request.QueryString["id"])).FirstOrDefault();
      
              var imageBytes = GetBytesFromUrl("http://api.screenshotmachine.com/?key=xxxxxx&size=F&url=http://xxxxxxx.com/a4.aspx?id=" + procad.ForSaleID);
               string root = Server.MapPath("~/");
      
                  // clean up the path
                  if (!root.EndsWith(@"\"))
                      root += @"\";
      
                  // make a folder to store the images in
                  string fileDirectory = root + @"\images\a4en\";
      
                  // create the folder if it does not exist
                  if (!System.IO.Directory.Exists(fileDirectory))
                      System.IO.Directory.CreateDirectory(fileDirectory);
      
              WriteBytesToFile( fileDirectory + + procad.ForSaleID + ".png", imageBytes);
      

      【讨论】:

        【解决方案4】:

        是的,我也尝试使用 wkhtmltopdf c# 包装器,但在 pdf 或图像转换时,我的电脑爱好者 goin crayz。我还必须上传服务器 exe 文件,而我的托管公司不支持它们

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2011-10-05
          • 1970-01-01
          • 1970-01-01
          • 2012-04-24
          • 1970-01-01
          • 2011-12-02
          • 2013-12-18
          相关资源
          最近更新 更多