Asp. C # Implementation of picture file and Base64string code decoding _ Practical skills

Source: Internet
Author: User
The picture of course is the existence of that JS file inside, so I opened the flashblocker.js, and then browse, find the following sentence:
var flash = ' Data:image/png;base64,ivborw0kggoaaaansuheugaaaiaaaacacayaa ... '
(small white) <span style= "Font-size:small" > This is the first time I recognize the use of Base64, remember the previous save the page, The total habit is saved in the. mht format, because this will save the pictures in the Web page, but always wonder why only one </SPAN>
View Sourceprint?<span style= "Font-size:small" > MHT file, open to have a picture, now know to save as a mht format all the pictures in the page into the Base64 string exists inside. </SPAN>
View Sourceprint?<span style= "Font-size:small" > </span><span style= "Font-size:small" > Implementation: </ Span>
View Sourceprint?<span style= "Font-size:small" > </SPAN >
In fact very simple, picture file to base64string conversion, only need convert class inside a tobase64string method can
Copy Code code as follows:

Image fromimage = Image.FromFile (Txtimg.text);
MemoryStream stream = new MemoryStream ();
Fromimage.save (Stream, imgformat[extension]);
Txtstring.text = Convert.tobase64string (stream. GetBuffer ());

Add here, seemingly icon file is not convertible (the results of their own test), need to change the words will be modified, curve save the Nation ~
The Convert.frombase64string () method is needed to extract pictures from base64string.
Copy Code code as follows:

MemoryStream stream = new MemoryStream (convert.frombase64string (Txtstring.text));
Bitmap img = new Bitmap (stream);
Img. Save (Txtimg.text);
MessageBox.Show ("completed!");

It seems that some comrades in the conversion back to a problem, the feeling should be defined stream when the problem, new when directly to the conversion of the byte[] to it, there should be no "beyond the scope of the expected" error. The conversion problem should not be related to the original artwork in Java or other languages. Because the base64 code should be the same.
Author: Mr. Fix
Source: http://1971ruru.cnblogs.com

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.