public static void GenerateCanvas(string imgSaveName, int canvasWidth, int canvasHeight, string imgData) { try { if (string.IsNullOrEmpty(imgData)) return; if (imgData.StartsWith("data:image/png;base64") == false) return; var base64 = imgData.Substring(22); byte[] bytes = Convert.FromBase64String(base64); MemoryStream memStream = new MemoryStream(bytes); BinaryFormatter binFormatter = new BinaryFormatter(); var img = System.Drawing.Image.FromStream(memStream); img.Save(imgSaveName); } catch (Exception ex) { } }