C # pictures and conversion of 64-bit encoding

Source: Internet
Author: User

/* Convert the picture to 64-bit encoding */


Find folder
System.IO.DirectoryInfo dd = new System.IO.DirectoryInfo ("C://qq");
Get all the files under the folder
system.io.fileinfo[] File = dd. GetFiles ();
Get the path to a file
String filePath = File[1]. DirectoryName + "\ \" + file[1]. Name;
Read this file with Streamread
System.IO.StreamReader sr = new StreamReader (FilePath, Encoding.default, true);

int index;
Instantiate a memory stream
System.IO.MemoryStream Tempstream = new MemoryStream ();
Converting a stream to a byte array
while (index = Sr. Basestream.readbyte ())! =-1)
{
Tempstream.writebyte (((byte) index));
}
byte[] array = Tempstream.toarray ();
Tempstream.close ();
Converts the resulting byte array to base64 bit encoding
string result = convert.tobase64string (array);

System.IO.File.WriteAllText ("c://zz.txt", result);


/* Convert 64-bit encoding to picture */

Converting 64-bit encodings to byte arrays
byte[] cc = convert.frombase64string (result);

Create a file with FileStream
FileStream fs = new FileStream ("C://a.jpg", FileMode.Create);

BinaryWriter bw = new BinaryWriter (FS);

Bw. Write (CC);

C # pictures and conversion of 64-bit encoding

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.