public JsonResult UploadEventImage(string uploadedFile)
Bitmap bmp= null; byte[] byteBuffer = Convert.FromBase64String(uploadedFile.Replace("data:image/png;base64,", "")); MemoryStream memoryStream = new MemoryStream(byteBuffer); memoryStream.Position = 0; bmp= (Bitmap)Bitmap.FromStream(memoryStream); memoryStream.Close(); memoryStream = null; byteBuffer = null; if (bmp!= null) { string fileName = "image1.jpg"; fileName = "~/Content/img/" + fileName; bmp.Save(Server.MapPath(fileName), System.Drawing.Imaging.ImageFormat.Bmp); } } 2) public JsonResult UploadEventImage(string uploadedFile){ <pre>Bitmap bmp= null; byte[] byteBuffer = Convert.FromBase64String(uploadedFile.Replace("data:image/png;base64,", "")); MemoryStream memoryStream = new MemoryStream(byteBuffer); memoryStream.Position = 0; bmp= (Bitmap)Bitmap.FromStream(memoryStream); Image img = bmp; Bitmap resizedImg = new Bitmap(img.Width, img.Height); double ratioX = (double)resizedImg.Width / (double)img.Width; double ratioY = (double)resizedImg.Height / (double)img.Height; double ratio = ratioX < ratioY ? ratioX : ratioY; int newHeight = Convert.ToInt32(img.Height * ratio); int newWidth = Convert.ToInt32(img.Width * ratio); using (Graphics g = Graphics.FromImage(resizedImg)) { g.DrawImage(img, 0, 0, newWidth, newHeight); } if (bmp!= null) { string fileName = "image1.jpg"; fileName = "~/Content/img/" + fileName; resizedImg.Save(Server.MapPath(fileName)); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)