Background:
A flashblocker script file was used in the opera forum a few days ago. As the name suggests, the Flash file in the webpage is filtered out. After filtering, an image is displayed in the original position, in the past, the flash filter plug-in used in Firefox was the same, and the displayed images were the same, so I wanted to change it.
Of course the image exists in the JS file, so I opened flashblocker. JS, browsed it, and found the following sentence:
VaR flash = 'data: image/PNG; base64, ivborw0kggoaaaansuheugaaaiaaaacacayaa ......'
(Tom)This is the first time I realized the use of base64. I remember that when I saved a webpage, I always used to save it. MHT format, because this will save the images in the web page, but it has been wondering why there is only one. the MHT file is opened, but there are images. Now, when we know that the image is saved in the MHT format, we convert all the images in the webpage into base64 strings.
Wikipedia:Http://zh.wikipedia.org/zh-cn/Base64
Implementation:
In fact, it is very simple. to convert an image file to base64string, you only need a tobase64string method in the convert class.
Image fromimage = image. fromfile (txtimg. text); memorystream stream = new memorystream (); fromimage. save (stream, imgformat [extension]); txtstring. TEXT = convert. tobase64string (stream. getbuffer ());
It seems that the icon file cannot be converted (the result of your own test). If you need to convert the icon, you have to change it. The curve saves the country ~
To extract an image from base64string, the convert. frombase64string () method is required,
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 encountered problems when switching back, and they thought it was a problem when defining stream. When new, they directly gave the converted byte [] to it, there should be no "beyond the expected range" error. Conversion Problems should be caused by the fact that the source image is generated in Java or other languages. Because base64 encoding is the same.