如何使用HTML标记构建图像?

时间:2023-02-15 00:28:19

I need to display reports and things in HTML using Microsoft's HTMLDocument object.

我需要使用Microsoft的HTMLDocument对象以HTML格式显示报表和内容。

Unfortunately, you can give the document HTML markup, but you cannot give it images. It is only able to display images you get from a URL, e.g.:

不幸的是,你可以给文档HTML标记,但你不能给它图像。它只能显示从URL获得的图像,例如:

  • http://
  • file://
  • res://

As a workaround I figured I could construct an image using HTML markup, pixel-by-colored pixel.

作为一种解决方法,我想我可以使用HTML标记,逐个像素的像素构建图像。

Has there been any work in this area? Should it be absolutely positioned 1x1 colored spans? A 350x200 table, with rows and columns both one-pixel in size?

这方面有没有工作?它应该绝对定位1x1彩色跨度吗?一个350x200的表,行和列的大小都是一个像素?

7 个解决方案

#1


Can you just use the Data URI scheme?

你能使用数据URI方案吗?

IE8 supports this (as do most newer browsers); your images would look like this:

IE8支持这一点(与大多数新版浏览器一样);你的图像看起来像这样:

<img src="data:image/png;base64,A0123...==">

where the A0123... stuff is a base64 representation of an image file. Depending on the language you're using, you may be able to take advantage of Convert.ToBase64String() to do much of the work for you.

其中A0123 ... stuff是图像文件的base64表示。根据您使用的语言,您可以利用Convert.ToBase64String()为您完成大部分工作。

#2


The simplest way, in my opinion, is to use a base64 encoded image. It's efficient enough, and there are tools to automate generation: http://www.greywyvern.com/code/php/binary2base64.

在我看来,最简单的方法是使用base64编码的图像。它足够高效,并且有自动生成的工具:http://www.greywyvern.com/code/php/binary2base64。

#3


People have, much to the horror of all, done some solid work in this area. The solution I link to uses tables with RLE compression, which seems smart enough to me.

令人恐惧的是,人们在这方面做了一些可靠的工作。我链接到的解决方案使用具有RLE压缩的表,这对我来说似乎足够聪明。

#4


First, a word of caution: this is an awful, terrible thing you are planning to do.

首先,要提醒一句:这是你计划要做的一件非常糟糕的事情。

Now that we've got that out of the way, I happen to have done a good deal of this terrible thing. I can tell you that you're best bet is to use tables, not divs or spans. Even so, it's terribly inefficient and takes forever to load, as you can see from the samples I linked to. Just don't do it, other than as a perverse joke.

现在我们已经完成了这个,我碰巧做了很多这个可怕的事情。我可以告诉你,你最好的选择是使用表格,而不是div或spans。即使这样,它也非常低效并且需要永远加载,正如您从我链接的示例中看到的那样。只是不要这样做,除了作为一个不正当的笑话。

#5


I wrote a PHP class a few years ago to do this, but I wouldnt recommend using this in the real world as it takes a long time for a browser to render a table big enough for an image.

几年前我写了一个PHP类来做这个,但我不建议在现实世界中使用它,因为浏览器需要很长时间才能为图像渲染一个足够大的表。

Unless I'm not understanding your question correctly, why can't you refer to the image using a full URL:

除非我没有正确理解您的问题,否则为什么不能使用完整的URL来引用图像:

http://somewhere.com/myimage.jpg

#6


"reports and things"... could be a bit clearer here...

“报道和事情”......在这里可能会更清楚一点......

If what you ultimately want to do is display a report which happens to be dynamically generated, chances are you can automatically generate an image of the report. 'Export to PDF' is probably available in the report tool. Crude, but simpler and more efficient than where you seem to be headed now.

如果您最终想要做的是显示一个恰好是动态生成的报告,您可以自动生成报告的图像。报告工具中可能提供“导出为PDF”。原油,但比你现在的目标更简单,更有效率。

#7


In IE only you can use VML which gives basic SVG-like vector drawing abilities.

在IE中,只有你可以使用VML,它提供类似SVG的基本矢量绘图功能。

This guy's created a javascript library to draw vector graphics in browsers using just sivs: http://web.archive.org/web/20080112113027/www.walterzorn.com/jsgraphics/jsgraphics_e.htm (site seems down at the moment)

这家伙创建了一个javascript库,用于在浏览器中使用sivs绘制矢量图形:http://web.archive.org/web/20080112113027/www.walterzorn.com/jsgraphics/jsgraphics_e.htm(网站现在看来很糟糕)

These days you could also try a library such as Raphaël which uses the brower's canvas or VML support.

这些天你也可以尝试使用Raphaël这样的库来使用浏览器的画布或VML支持。

#1


Can you just use the Data URI scheme?

你能使用数据URI方案吗?

IE8 supports this (as do most newer browsers); your images would look like this:

IE8支持这一点(与大多数新版浏览器一样);你的图像看起来像这样:

<img src="data:image/png;base64,A0123...==">

where the A0123... stuff is a base64 representation of an image file. Depending on the language you're using, you may be able to take advantage of Convert.ToBase64String() to do much of the work for you.

其中A0123 ... stuff是图像文件的base64表示。根据您使用的语言,您可以利用Convert.ToBase64String()为您完成大部分工作。

#2


The simplest way, in my opinion, is to use a base64 encoded image. It's efficient enough, and there are tools to automate generation: http://www.greywyvern.com/code/php/binary2base64.

在我看来,最简单的方法是使用base64编码的图像。它足够高效,并且有自动生成的工具:http://www.greywyvern.com/code/php/binary2base64。

#3


People have, much to the horror of all, done some solid work in this area. The solution I link to uses tables with RLE compression, which seems smart enough to me.

令人恐惧的是,人们在这方面做了一些可靠的工作。我链接到的解决方案使用具有RLE压缩的表,这对我来说似乎足够聪明。

#4


First, a word of caution: this is an awful, terrible thing you are planning to do.

首先,要提醒一句:这是你计划要做的一件非常糟糕的事情。

Now that we've got that out of the way, I happen to have done a good deal of this terrible thing. I can tell you that you're best bet is to use tables, not divs or spans. Even so, it's terribly inefficient and takes forever to load, as you can see from the samples I linked to. Just don't do it, other than as a perverse joke.

现在我们已经完成了这个,我碰巧做了很多这个可怕的事情。我可以告诉你,你最好的选择是使用表格,而不是div或spans。即使这样,它也非常低效并且需要永远加载,正如您从我链接的示例中看到的那样。只是不要这样做,除了作为一个不正当的笑话。

#5


I wrote a PHP class a few years ago to do this, but I wouldnt recommend using this in the real world as it takes a long time for a browser to render a table big enough for an image.

几年前我写了一个PHP类来做这个,但我不建议在现实世界中使用它,因为浏览器需要很长时间才能为图像渲染一个足够大的表。

Unless I'm not understanding your question correctly, why can't you refer to the image using a full URL:

除非我没有正确理解您的问题,否则为什么不能使用完整的URL来引用图像:

http://somewhere.com/myimage.jpg

#6


"reports and things"... could be a bit clearer here...

“报道和事情”......在这里可能会更清楚一点......

If what you ultimately want to do is display a report which happens to be dynamically generated, chances are you can automatically generate an image of the report. 'Export to PDF' is probably available in the report tool. Crude, but simpler and more efficient than where you seem to be headed now.

如果您最终想要做的是显示一个恰好是动态生成的报告,您可以自动生成报告的图像。报告工具中可能提供“导出为PDF”。原油,但比你现在的目标更简单,更有效率。

#7


In IE only you can use VML which gives basic SVG-like vector drawing abilities.

在IE中,只有你可以使用VML,它提供类似SVG的基本矢量绘图功能。

This guy's created a javascript library to draw vector graphics in browsers using just sivs: http://web.archive.org/web/20080112113027/www.walterzorn.com/jsgraphics/jsgraphics_e.htm (site seems down at the moment)

这家伙创建了一个javascript库,用于在浏览器中使用sivs绘制矢量图形:http://web.archive.org/web/20080112113027/www.walterzorn.com/jsgraphics/jsgraphics_e.htm(网站现在看来很糟糕)

These days you could also try a library such as Raphaël which uses the brower's canvas or VML support.

这些天你也可以尝试使用Raphaël这样的库来使用浏览器的画布或VML支持。