Home >Backend Development >C#.Net Tutorial >Convert pictures to BASE64 code in C#
//The image is converted to base64 encoded text
using using using using out out out through '' out's ’ ’ through ‐ through off‐line ‐‐‐‐‐ off to base64 encoded text
dlg.Title = "Select the picture you want to convert" ;
dlg.Filter = "Image files (*.jpg;*.bmp;*.gif;*.png)|*.jpg*.jpeg;*.gif;*.bmp|AllFiles (*.*)|* .*";
if (DialogResult.OK == dlg.ShowDialog())
ToString());
.
try
Image = bmp; MemoryStream ms = new MemoryStream();
bmp.Save(ms , System.Drawing.Imaging.ImageFormat.Jpeg); byte[] arr = new byte[ms.Length]; Length); sw.Close();
. Conversion successful!");
}
catch (Exception
private void button2_Click(object sender, EventArgs e)
viadlg.Title = "Select base64-encoded text to convert";
dlg.Filter = "txt files|*.txt";
for (int i = 0; i Base64StringToImage(string txtFileName)
StreamReader sr = new StreamReader(ifs);
StreamReader sr = sr.ReadToEnd() ;
byte[] arr = Convert.FromBase64String(inputStr); //bmp.Save(txtFileName + ".jpg", (System.Drawing.Imaging.ImageFormat.Jpeg); //bmp.Save(txtFileName + ".png", ImageFormat.Png); This.pictureBox2.Image = bmp;
if (File.exists (txtFilename)) {
File.delete (txtFilename);
}
//messageBox.show ("Converted success! "); }
}