} // End Function Crop public override System.IO.Stream ResizeImage( System.IO.Stream inputStream, System.IO.Stream outputStream, SaveFormat saveFormat, float ratio, System.Drawing.Size?maxSize) { SixLabors.ImageSharp.Image <SixLabors.ImageSharp.Rgba32> img = SixLabors.ImageSharp.Image.Load(inputStream); SixLabors.Primitives.SizeF oldSizeSize = img.Size(); if (maxSize.HasValue) { float ratioX = (float)maxSize.Value.Width / (float)img.Width; float ratioY = (float)maxSize.Value.Height / (float)img.Width; ratio = ratioX < ratioY ? ratioX : ratioY; } // End if (maxSize.HasValue) SixLabors.Primitives.SizeF newSize = oldSizeSize * ratio; if (outputStream == null) { outputStream = new System.IO.MemoryStream(); } // Compand: whether to compress or expand individual pixel color values img.Mutate(x => x.Resize((SixLabors.Primitives.Size)newSize, KnownResamplers.Bicubic, false)); img.Save(outputStream, GetEncoder(saveFormat)); // NO, no seek, if we're respone.OutputStream if (outputStream.CanSeek) { outputStream.Seek(0, System.IO.SeekOrigin.Begin); } return(outputStream); } // End Function ResizeImage