Here’s the code for saving a base64 encoded string to image file in C#. You can to convert a base64 string into PNG format in C# by following code. You may also like: C# Image File to Base64 String Base64 To PNG in C# (Save Base64 String to Png Image).
1. Overview
ln this quick guide, we're going to protect how to encode image document to a Bottom64String, then decode it to obtain the initial image making use of Apache Common IO and Coffee 8 native Base64 features.
This operation could be used for any binary data files or binary arrays. It'h helpful when we require to exchange binary content material in JSON format such as from cellular app to Sleep endpoint.
For more details about Foundation64 transformation, check out out this post here.
2. Expert Dependency
Allow's include the pursuing dependencies to thépom.xmIfile:
You can find the most recent edition of Apache Cómmons IO on Maven Main.
3. Change Image File to Base64Thread
First of all, allow's examine the file content to a byte number and use Coffee 8Base64course to éncode it:
ThéencodedStringis certainly aChainof character types in the collection of<ém>A-Zá-z0-9+/ém>, and the decoder rejects any heroes outside of this collection.
4. Switch Bottom64Stringto Image File
Now we possess a Foundation64String, let's decode it back to binary content material and compose to a brand-new document:
5. Testing Our Code
Finally, we can verify that the program code is functioning correctly by reading through a file, coding it to a Base64Chain, and solving it back to a fresh document:
6. Summary
This tó-the-point write-up describes the basic of encoding any file's content to a Bottom64Chain, and decoding a Foundation64Threadto a byte assortment and save it to a file making use of Apache Normal IO and Coffee 8 features.
As generally, program code snippets can be discovered over ón GitHub.