如何将图像转换到字符流如何将、字符、图像转换

2023-09-05 02:07:35 作者:南邮

我发现,图像可以存储为一些字符串。要举一个例子,我已经包括了微软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.

推荐答案

Base64的EN $ C C的字节数组$

Convert.ToBase64String(b);
 
精彩推荐
图片推荐