ImageBase64Encoder is a versatile C# class that makes it simple to convert images to Base64 strings and vice versa. It is particularly useful for embedding images in HTML or CSS, transmitting images over a network, or storing them in databases. This class is built on top of the powerful SixLabors.ImageSharp library, ensuring top-notch performance and reliability.
Easily convert images to Base64 strings and back Supports loading images from file paths or byte arrays Lightweight and efficient with the help of SixLabors.ImageSharp Compatible with various image formats, automatically handled by the ImageSharp library Installation To use this class, you need to install the SixLabors.ImageSharp NuGet package:
Install-Package SixLabors.ImageSharp -Version 1.0.4
Then, simply add the ImageBase64Encoder.cs file to your project.
Here are a few examples of how to use the ImageBase64Encoder class:
using Com.DotNetBros.ImageBase64Encoder;
string imagePath = "path/to/your/image.png";
string base64String = ImageBase64Encoder.ImageToBase64(imagePath);
Console.WriteLine("Base64 String: " + base64String);using Com.DotNetBros.ImageBase64Encoder;
byte[] imageBytes = File.ReadAllBytes("path/to/your/image.png");
string base64String = ImageBase64Encoder.ImageToBase64(imageBytes);
Console.WriteLine("Base64 String: " + base64String);using Com.DotNetBros.ImageBase64Encoder;
string base64String = "your_base64_string_here";
Image image = ImageBase64Encoder.Base64ToImage(base64String);
// Perform any additional image processing or save it to a file
image.Save("output_image.png");More information about Base64: https://www.dotnetbros.com/boost-your-web-performance-with-base64-image-encoding/
This project is open source and available under the MIT License.
Pull requests and suggestions are welcome! If you have any ideas or improvements, please don't hesitate to submit an issue or create a pull request.