如题所示,直接上代码。C#
string base64Str = "data:image/jpeg;base64,/9j/4AAQSk略略略略略duDs2Q==";//略,字符太长,在线转一个图片测试吧
string filePath = HttpContext.Current.Server.MapPath("~/Image/" + DateTime.Now.Year.ToString() + "/" + DateTime.Now.Month.ToString("D2") + "/" );
if (!string.IsNullOrEmpty(base64Str))
{
int startIndex = base64Str.IndexOf(',');
string imgBase64 = base64Str.Substring(startIndex + 1); //获取data:image/jpeg;base64,后的正文
int typestartIndex = base64Str.IndexOf("/");
int typeEndIndex = base64Str.IndexOf(";");
string type = base64Str.Substring(typestartIndex + 1, typeEndIndex - typestartIndex - 1);//获取图片类型