我使用HtmlRenderer从html标记生成jpg图像。然而,它没有从CSS应用背景图像:HtmlRenderer不会呈现来自css的背景图像
<div style="background:url(https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcTbNHtYU6bKKmxkJXlqDr7y7afZyZtw-WwDg6DoUNCb9nElkplEuw); width: 440px; height: 361px">
Some content here.
</div>
下面是C#代码:
String ecardHtml = File.ReadAllText("testWithGoodImage.html");
using (Image img = HtmlRender.RenderToImageGdiPlus(ecardHtml, maxWidth: 440, textRenderingHint: TextRenderingHint.AntiAliasGridFit))
{
img.Save("result.jpg");
}
调试表明,图像甚至没有要求,所以我怀疑它不支持。但<img>
元素确实很好。
所以问题是如何使它工作。
我知道我可以在HtmlRenderer中的图像上呈现html,但我只想在html代码中拥有所有标记。
http://www.codeproject.com/Articles/32376/A-Professional-HTML-Renderer-You-Will-使用,不确定,但它只说支持背景颜色! –