需要打开一个图像在网络浏览器中打开

问题描述:

byte.eml文件是有图像base64编码值..我打算在浏览器中打开它...但这不是填充图像文件.... plz帮助我出..需要打开一个图像在网络浏览器中打开

这是代码...
昏暗OFILE由于有System.IO.File 昏暗俄瑞阿得斯作为就是System.IO.StreamReader

orEAD = oFile.OpenText("E:\mailbox\P3_hemantd.mbx\byte.eml") 
Dim content As String 
content = "" 

''Dim intsinglechr As Integer 
''Dim csinglechr As String 

While orEAD.Peek <> -1 
    content = content & Chr(orEAD.Read) 
    content = Replace(content, vbCrLf, "") 
    content = Replace(content, vbTab, "") 
    content = Replace(content, " ", "") 

End While 
Response.ContentType = "image/jpeg" 
Response.BinaryWrite(Convert.FromBase64String(content)) 

是否功能Convert.FromBase64String(内容)的工作是否正确?尝试写入文件。

+0

其工作,但它产生但结果是出乎意料....例如 JFIF; CREATOR:GD-JPEG V1.0(使用IJG JPEG V62),质量= 85 C!“$”$ 我想写它像...这给错误 Response.WriteFile(Convert.FromBase64String(content)) 错误。 类型'字节的1维数组'的值不能被转换为'字符串' 有一件事我希望你清除byte.eml文件只有基地64加密的图像file.i尝试它从diff实用程序转换this工作.so需要asp.net编码处理基于文件的解码 – manish 2010-05-02 12:48:18

问题是byte.eml的内容不是base64编码图像,它是一个MIME文档。

你需要解析MIME文件,然后然后得到你的图像。

您可以谷歌“C#MIME MAIL PARSING”。

下面是相关SO question让你开始

UPDATE

好了,让我们假设你实际上有一个形象的有效表示为Base64串...

<%@ Page Language="VB" %> 

<%@ Import Namespace="System.IO" %> 

<script runat="server"> 
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load 


     Dim bytes As Byte() = File.ReadAllBytes(Server.MapPath("Chrysanthemum.jpg")) 
     Dim base64 As String = Convert.ToBase64String(bytes) 

     '' base64 is what you say you have 


     Dim newBytes As Byte() = Convert.FromBase64String(base64) 
     Response.ClearContent() 
     Response.ClearHeaders() 
     Response.ContentType = "image/jpeg" 
     Response.BinaryWrite(newBytes) 
     Response.End() 

    End Sub 

</script> 

此代码的工作原理是,如果用base64代替文本,但它不起作用,则表示图像没有有效的base64字符串表示形式。

更新2

这将读取你说的base64包含并将其写入到响应的文本文件。

如果仍然不工作,那么你有一个问题要问:

如何正确提取一个MIME电子邮件64基部分?

<%@ Page Language="VB" %> 
<%@ Import Namespace="System.IO" %> 
<script runat="server"> 
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load 

     Dim base64 As String = File.ReadAllText("E:\mailbox\P3_hemantd.mbx\byte.eml") 

     Dim newBytes As Byte() = Convert.FromBase64String(base64) 
     Response.ClearContent() 
     Response.ClearHeaders() 
     Response.ContentType = "image/jpeg" 
     Response.BinaryWrite(newBytes) 
     Response.End() 
    End Sub 
</script> 
+0

byte.eml文件只有基地64编码图像...我从eml文件中提取它。现在我打开它通过asp.net打开web浏览器。 ...但我没有得到结果......帮我想我有txt文件内容基地64编码image.eg “R0lGODlhagAwAOZ /暗呼+ uLj4wZ0b4yT + oaHitfX11hj + H + H + xMn6Oj29xzVy9L19BHGvauw + ZVF 8sjIyEhV + Efaz2pvozKf3b29vQ0m1v7 +/u7u7gWJgwlgqoOzsSo67yTd0yXXzODi + wV/............“ 所以发送我的确切的asp。用于将基础64编码文本转换为图像的网络代码。 – manish 2010-05-02 12:38:23

+0

老板你是伟大的...我试着你的代码..和它的工作...我花了10小时后有点快乐事情发生了....让我看 我的代码说什么.... 你会帮我一次..... 给我的代码读取TXT文件内容,并将其转换字节 我要求更换这个.. 昏暗的字节为字节()= File.ReadAllBytes(服务器。我想要存储在base64我的文件内容 – manish 2010-05-02 13:07:06

+0

谢谢你FREND我解决了我的问题.... 谢谢很多.....我需要你的邮件...... f或进一步的帮助... – manish 2010-05-02 13:25:20