C#:如何将内存流设置为 asp.net 图像控件的源属性?

发布于 2024-10-07 05:53:38 字数 84 浏览 0 评论 0原文

我在一个 ASP.NET 页面中有一个 ASP.NET 图像控件,并且有一个包含图像的内存流。如何转换此内存流以将其设置为图像源,而不将图像存储在硬盘中?

I have an asp.net image control in one ASP.NET page and have a Memory Stream which has an image.How can i convert this memory stream to set it as the image source without storing the image in the hard disk ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

小傻瓜 2024-10-14 05:53:38

图像控件采用 ImageUrl- 图像所在的路径。

没有任何属性可以获取实际图像(或图像数据)。

您可以做的是编写一个 HttpHandler ,它将从任何来源流式传输您的图像 - 设置 ImageUrl 以使用此处理程序。

这里是使用内存流的通用文件处理程序的示例- 这是我建议的一个很好的起点。

The image control takes an ImageUrl - a path to where the image is located.

There is no property that takes an actual image (or image data).

What you can do is write a HttpHandler that will stream your images from whatever source - set the ImageUrl to use this handler.

Here is an example for a general file handler using a memory stream - it's a good starting point for what I suggest.

对你而言 2024-10-14 05:53:38

您必须将该文件写入磁盘或创建另一个页面(同一页面上的操作?),将 MemoryStream 的内容写入响应,然后将图像控件指向该源。

you'll have to either write that file onto disk or make another page (action on the same page?) that writes the content of your MemoryStream into the Response, and then point the image control to that source.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文