1

我正在用 C# 开发一个 .NET 3.5 WinForms 项目,我想就直接从内存中的源在WebBrowser控件中呈现图像的最佳方法提出意见? 通过内存,我的意思是我有一组Base64编码字符串格式的图像,我希望将它们呈现在 WebBrowser 控件的嵌入页面上。

我曾希望使用嵌入式数据 URI选项示例,但是这种方法仅限于图像 < 32KB。

我希望可以将其转换为System.Drawing.Image实例并以某种方式在srchtml 标记中引用此图像,如下所示<img src="<insert reference here?>" </img>:这样的技术可行吗?

如果不可能做到这一点,那么我想知道在 windows 临时目录中创建文件并从那里引用的可行性?

4

1 回答 1

1

Another approach is to set up a web server and to load the image via the localhost <img src='http://localhost/img.jpg'>. This prevents creating temporary images images on disk.

If you don't want to deal with a web server, simple image tiling combined with the mentioned data URI parameter would work. A single tile can be obtained by:

Rectangle region = new Rectangle(x, y, tileWidth, tileHeight);
Bitmap tile = sourceBitmap.Clone(region, sourceBitmap.Clone.PixelFormat);

You just repeat the tile generation for varying parameters of Rectangle region until you have covered the complete source image. You might try out which tileWidth and tileHeight are appropriate to result in tiles with data size lower than 32kB.

于 2013-01-15T10:47:28.000 回答