Convert an image into hexadecimal code

Source: Internet
Author: User
Using system. IO;
Write text files from images!
Private void button#click (Object sender, system. eventargs E)
{
Filestream FS = NULL;
Binaryreader BR = NULL;
Streamwriter Sw = NULL;

Try
{

FS = new filestream ("aa.bmp", filemode. Open, fileaccess. Read );
BR = new binaryreader (FS );
Sw = new streamwriter ("bb.txt ");
Int length = (INT) fs. length;
While (length> 0)
{
Byte tempbyte = Br. readbyte ();
Int tempint = convert. toint32 (tempbyte );
String tempstr = convert. tostring (tempint, 16 );
Sw. writeline (tempstr );
Length --;
}


}
Catch (exception exce)
{
MessageBox. Show (exce. Message );
}
Finally
{
Sw. Close ();
BR. Close ();
FS. Close ();
}

}
Read from text and restore to image!
Private void button2_click (Object sender, system. eventargs E)
{

Filestream FS = NULL;
Binarywriter BW = NULL;
Streamreader sr = NULL;
Try
{
FS = new filestream ("cc.bmp", filemode. Create, fileaccess. Write );
BW = new binarywriter (FS );
Sr = new streamreader ("bb.txt ");
While (Sr. Peek ()! =-1)
{
String tempstr = Sr. Readline ();
Int tempint = convert. toint16 (tempstr, 16 );
Byte tempbyte = convert. tobyte (tempint );
Bw. Write (tempbyte );
}

}
Catch (exception exce)
{

MessageBox. Show (exce. Message );
}
Finally
{
Sr. Close ();
Bw. Close ();
FS. Close ();
}

}

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.