public Byte[] CreateThumbnail(byte[] imageData, int Width, int Height, bool maintainAspectRatio) { Byte[] imageDataNew; Bitmap bmp = null; try { MemoryStream memStream = new MemoryStream(imageData); System.Drawing.Image img = System.Drawing.Image.FromStream(memStream); if (maintainAspectRatio) { AspectRatio aspectRatio = new AspectRatio(); aspectRatio.WidthAndHeight(img.Width, img.Height, Width, Height); bmp = new Bitmap(img, aspectRatio.Width, aspectRatio.Height); } else { bmp = new Bitmap(img, Width, Height); } memStream.Dispose(); MemoryStream stream = new MemoryStream(); bmp.Save(stream, System.Drawing.Imaging.ImageFormat.Bmp); imageDataNew = stream.ToArray(); } catch (Exception ex) { string ErrorMsg = ex.Message.ToString(); imageDataNew = imageData; } return(imageDataNew); }
public Bitmap CreateThumbnail(byte[] imageByte, bool maintainAspectRatio, int desiredWidth, int desiredHeight) { Bitmap bmp = null; MemoryStream memStream = new MemoryStream(imageByte); System.Drawing.Image img = System.Drawing.Image.FromStream(memStream); if (maintainAspectRatio) { AspectRatio aspectRatio = new AspectRatio(); aspectRatio.WidthAndHeight(img.Width, img.Height, desiredWidth, desiredHeight); bmp = new Bitmap(img, aspectRatio.Width, aspectRatio.Height); } else { bmp = new Bitmap(img, desiredWidth, desiredHeight); } memStream.Dispose(); return(bmp); }