My aim is to convert a base64 string into an image and save it to the disk. I have the following code (mostly from this SO answer) -
namespace ImageSaver
{
using System;
static class Program
{
public static void LoadImage()
{
//get a temp image from bytes, instead of loading from disk
//data:image/gif;base64,
//this image is a single pixel (black)
byte[] bytes = Convert.FromBase64String("R0lGODlhAQABAIAAAAAAAAAAACH5BAAAAAAALAAAAAABAAEAAAICTAEAOw==");
Image image;
Bitmap bimage;
using (MemoryStream ms = new MemoryStream(bytes))
{
image = Image.FromStream(ms);
}
bimage = new Bitmap(image);
bimage.Save("c:\\img.gif", System.Drawing.Imaging.ImageFormat.Gif);
}
static void Main(string[] args)
{
ImageSaver.Program.LoadImage();
}
}
}
I ran it on MS Visual Studio 2010 Ultimate (Windows 8.1 Pro x64), without errors, but I could not find the image file in C drive. Where did I go wrong?