private async Task <BoxExtractionResult> ExtractBoxAsync( Image image, BoxExtractionInput input, ThumbnailSizeName thumbnailSize, CancellationToken cancellationToken) { var face = new BoxExtractionResult(); int width = input.Box.Right - input.Box.Left; int height = input.Box.Bottom - input.Box.Top; double multi = 1.95; var widthAdd = (int)((width * multi - width) / 2); //Make height and width same var heighAdd = Math.Abs(widthAdd + width - height); var faceBox = new ImageBox(); faceBox.Left = input.Box.Left - widthAdd; if (faceBox.Left < 0) { faceBox.Left = 0; } faceBox.Right = input.Box.Right + widthAdd; if (faceBox.Right > image.Width) { faceBox.Right = image.Width; } faceBox.Top = input.Box.Top - heighAdd; if (faceBox.Top < 0) { faceBox.Top = 0; } faceBox.Bottom = input.Box.Bottom + heighAdd; if (faceBox.Bottom > image.Height) { faceBox.Bottom = image.Height; } var rect = new Rectangle( faceBox.Left, faceBox.Top, faceBox.Right - faceBox.Left, faceBox.Bottom - faceBox.Top); Image croped = image.Clone(x => x.Crop(rect)); ThumbnailResult faceThumb = await _thumbnailService.GenerateThumbnailAsync( croped, thumbnailSize, cancellationToken); return(new BoxExtractionResult { Id = input.Id, Thumbnail = faceThumb }); }
public async Task <IEnumerable <SampleMedia> > GetSampleMediaListAsync() { foreach (SampleMedia sample in _samples) { using var fileStream = new FileStream(sample.Path, FileMode.Open); ThumbnailResult thumb = await _thumbnailService .GenerateThumbnailAsync( fileStream, ThumbnailSizeName.M, default); sample.Thumbnail = thumb.Data.ToDataUrl("jpg"); } return(_samples); }