简体   繁体   English

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

[英]How can I construct images using HTML markup?

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. 不幸的是,您可以给文档HTML标记,但是不能给它图像。 It is only able to display images you get from a URL, eg: 它只能显示从URL获得的图像,例如:

  • http:// http://
  • file:// 文件://
  • res:// 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? 是否应该绝对定位1x1彩色跨度? A 350x200 table, with rows and columns both one-pixel in size? 一个350x200的表格,行和列的大小均为一像素?

Can you just use the Data URI scheme ? 您可以只使用数据URI方案吗?

IE8 supports this (as do most newer browsers); IE8支持此功能(大多数较新的浏览器都支持); your images would look like this: 您的图像如下所示:

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

where the A0123... stuff is a base64 representation of an image file. 其中A0123...内容是图像文件的base64表示形式。 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. 根据您使用的语言,您也许可以利用Convert.ToBase64String()为您完成许多工作。

The simplest way, in my opinion, is to use a base64 encoded image. 我认为最简单的方法是使用base64编码的图像。 It's efficient enough, and there are tools to automate generation: 它足够高效,并且有一些工具可以自动生成: http://www.greywyvern.com/code/php/binary2base64 . http://www.greywyvern.com/code/php/binary2base64

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压缩的表,这对我来说似乎足够聪明。

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. 我可以告诉你,最好的选择是使用表格 ,而不是div或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. 只是不做,除了作为一个恶作剧。

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 http://somewhere.com/myimage.jpg

"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. 报告工具中可能提供了“导出为PDF”。 Crude, but simpler and more efficient than where you seem to be headed now. 粗略,但比您现在所要去的地方更简单,更高效。

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支持。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM