如何将图像转换到字符流 [英] How to convert an image in to a stream of characters

查看:236
本文介绍了如何将图像转换到字符流的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现,图像可以存储为一些字符串。要举一个例子,我已经包括了微软Word一部分已经在image.I保存一个Word文件,图像,并将其保存为XML格式。当我打开我得到了下面的一个记事本的XML文件部分。它必须是图像存储为文本的某些流。 有没有一种类似的方式来做到这一点在.NET。

I have found that an image can be stored as some string .To give an example I have included a ms word part that has an image.I saved a word file with image and saved it as xml format .when i opened the xml file in a notepad i got following section .It must be the image being stored as some stream of text. Is there a similar way to do it in .net.

<pkg:part pkg:name="/word/media/image1.png" pkg:contentType="image/png" pkg:compression="store">
    <pkg:binaryData>
      iVBORw0KGgoAAAANSUhEUgAAAMgAAAA2CAMAAAC1HibFAAADAFBMVEWlweL95Mn90qXs8vn7woTi
      6/b7unT94sO8oIP93br4okTJjExJgsS9mXT5rVr7xYr4mzaStdz+/v/5qlT3kiT7vnuCqdb7zZv8
      1aqXqb5GgMP4nTt6mLpMhMX//Pn/+vT/s1n/4rU+fMH+8eXT4fH1+PyTqsb++PGXl5n3lSpQh8b9
      6tVLg8T3iRP6sWO80el5o9OpxOP+7t3+9uz+2rLC1ez+7Nmbut6yyub+9On5pUqQt+P3jh2SmqNE
      ...Truncated for easy reading...
      ex9vtLWG320M9N9gHow3tv8BO9hrVo7LVzgAAAAASUVORK5CYII=
    </pkg:binaryData>
</pkg:part>

我曾尝试以下方法

I have tried following way

 Bitmap bmp = new Bitmap(@"D:/bmp.bmp");
    MemoryStream mem = new MemoryStream();
    byte[] b = mem.ToArray();

但它给我一个字节数组,而不是characters.If是人物,我可以在许多方面使用如保存在XML格式,使用SQL INSERT在一个blob的VARCHAR INSEAD插入图像。等等。

But it give me a byte array instead of characters.If it was characters ,I could use it in many ways such as saving in xml format , using sql insert to insert image in a varchar insead of a blob. etc.

推荐答案

<一个href="http://www.dailycoding.com/Posts/convert_image_to_base64_string_and_base64_string_to_image.aspx"相对=nofollow> Base64的EN $ C C的字节数组$

Convert.ToBase64String(b);

这篇关于如何将图像转换到字符流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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