使用memoryStream显示图像 [英] Displaying Image using memoryStream

查看:126
本文介绍了使用memoryStream显示图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所有



这里我用来显示图像使用流



我的代码来保存

all

here i am using to show image using stream

my code to save

System.IO.Stream fs = fuImage.PostedFile.InputStream;
                    System.IO.BinaryReader br = new System.IO.BinaryReader(fs);
                    Byte[] bytes = br.ReadBytes((Int32)fs.Length);
                    string base64String = Convert.ToBase64String(bytes, 0, bytes.Length);
                    Image1.ImageUrl = base64String;





i对此没有任何疑问



我的代码要Retrive





i have no prob this one

my code to Retrive

byte[] bytes = Encoding.ASCII.GetBytes(Dtab.Rows[0]["photo"].ToString());
            MemoryStream ms = new MemoryStream(bytes);
            Image1.ImageUrl = Convert.ToBase64String(ms.ToArray(), 0, ms.ToArray().Length);





它没有错误但没有在图像控制中显示图像



谢谢!



it complied without error but not showing image in image control

Thanks !

推荐答案

不显示图像的代码片段完全没有意义。你检索一些字符串(谁知道它里面存储了什么?),将它序列化为字节,假设它是ASCII(我怎么知道它存储为ASCII?)然后将其序列化为字节,最糟糕的是,编码是到base64。但任何文本的base64功能原则上都不能是任何URL。这仍然是一个难题你在这段代码背后的想法,更好地问自己。



怎么办?它取决于列名称photo下第0行中存储的内容,是否与任何图像相关或不相关,以及它在字符串中表示的形式。再一次,问问自己。



-SA
The fragment of code which is "not showing image" makes no sense at all. You retrieve some string (who knows what was stored in it?), serialize it into byte assuming it was ASCII (how can I know it was stored as ASCII?) and then serialize it into bytes, and, the worst part, encode is to base64. But base64 function of any text cannot be any URL in principle. It remains a puzzle what was you idea behind this fragment of code, better ask yourself about it.

What to do? It depends on what was stored in row 0 under the columns name "photo", was it related to any image at all or not, and it what form it was represented in the string. Again, ask yourself about it.

—SA


这篇关于使用memoryStream显示图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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