#region picture to Base64 encoded string
public string imgtobase64string (string imagefilename)
{
Try
{
Bitmap bmp = new Bitmap (imagefilename);
MemoryStream ms = new MemoryStream ();
Bmp. Save (MS, System.Drawing.Imaging.ImageFormat.Jpeg);
byte[] arr = new Byte[ms. Length];
Ms. Position = 0;
Ms. Read (arr, 0, (int) Ms. Length);
Ms. Close ();
return convert.tobase64string (arr);
}
catch (Exception ex)
{
return null;
}
}
#endregion
#region Base64 encoded string to picture
public void Base64stringtoimage (string strbase64)
{
Try
{
byte[] arr = convert.frombase64string (strbase64);
MemoryStream ms = new MemoryStream (arr);
System.Drawing.Image img = System.Drawing.Image.FromStream (ms);
String ls_path = Server.MapPath (@ "images\camera\" + Ls_imagenamecamera + ". jpg");
Img. Save (Ls_path, System.Drawing.Imaging.ImageFormat.Jpeg);
System.Drawing.Image img = System.Drawing.Image.FromStream (ms);
Img. Save ("Imgname.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
Img. Save ("Imgname.bmp", imageformat.bmp);
Img. Save ("Imgname.gif", imageformat.gif);
Img. Save (@ "Images\imgname.png", imageformat.png);
session["Imagenamecamera"] = Ls_imagenamecamera;
}
catch (Exception ex)
{
}
}
#endregion
Convert picture to BASE64 encoding in C #, BASE64 encoding to picture