如何在流中保存图像并将其放入ImageUrl [英] How to save an image in stream and put it in ImageUrl

查看:65
本文介绍了如何在流中保存图像并将其放入ImageUrl的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

在我的ASP.NET项目中,

我想将图像保存在流中而不是特定的路径中,并将图像从流中放入Image控件的imageUrl属性中.

就像代码一样:

Hi every body,

In my ASP.NET project,

I would like to save an image in stream instead of specific path and put this image from the stream into imageUrl property of an Image control.

Like the code:

System.Drawing.Bitmap bitmap= new System.Drawing.Bitmap(ImagePath);        
bitmap.Save(MyStream, System.Drawing.Imaging.ImageFormat.Jpeg);        
MyIamgeControl.ImageUrl = MyStream;

推荐答案

您不能将Stream对象分配给Image控件的ImageUrl属性只是因为对其进行了处理"的类型为string.

但是,您可以编写自定义的 HttpHandler ,它将为动态流返回Image Url.

http://stackoverflow.com/questions/46788/how-to-将内存绑定到aspimage控件
You can not assign Stream object to ImageUrl property of Image control is simply bacuase it''s Type is string.

However you can write your custom HttpHandler which will return Image Url for your dynamic stream.

http://stackoverflow.com/questions/46788/how-to-bind-a-memorystream-to-aspimage-control


不,它不能那样工作.流是仅存在于应用程序内存空间中的临时对象-无法将其分配为URL,因为它是临时对象:一旦myStream超出范围,它可以被销毁-可能在方法的结尾,或者可能是在页面加载完成时.

您要达到什么目的,以为您认为自己需要这个?
No, it doesn''t work like that. A stream is a temporary object existing only in the memory space of your application - it can''t be assigned as a URL because it is a transitory object: it can be destroyed as soon as myStream goes out of scope - which could be at the end of the method, or could be when your page load has completed.

What are you trying to achieve that you think you need this?


这篇关于如何在流中保存图像并将其放入ImageUrl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆