/// <summary> /// /// </summary> /// <param name="bytes"></param> /// <returns></returns> public Scale GetScale(byte[] bytes) { var scale = new Scale(); using (var source = Converter.GetBitmap(bytes)) { if (source != null) { scale.Height = source.Height; scale.Width = source.Width; } } return scale; }
/// <summary> /// create a new bitmap with new dimnesions from an existing picture /// </summary> /// <param name="source"></param> /// <param name="scale"></param> /// <returns></returns> public byte[] CreateResizedPicture(dynamic pic, Scale scale) { using (var source = new Bitmap(pic)) { using (var resized = new Bitmap(scale.Width, scale.Height)) { using (var graphics = Graphics.FromImage(resized)) { using (var ms = new MemoryStream()) { graphics.SmoothingMode = SmoothingMode.AntiAlias; graphics.InterpolationMode = InterpolationMode.HighQualityBicubic; graphics.PixelOffsetMode = PixelOffsetMode.HighQuality; graphics.DrawImage(source, new Rectangle(0, 0, scale.Width, scale.Height)); resized.Save(ms, ImageFormat.Png); return ms.ToArray(); } } } } }