public async Task <IActionResult> TileImage([FromForm] ImageTileDTO imageTileDTO) { try { var sw = new Stopwatch(); sw.Start(); var timestamps = new TimestampDTO(); if (imageTileDTO.Image.Length <= 0) { return(BadRequest()); } using var memStream = new MemoryStream(); await imageTileDTO.Image.CopyToAsync(memStream); timestamps.t1 = sw.ElapsedMilliseconds; using var image = new Bitmap(memStream); timestamps.t2 = sw.ElapsedMilliseconds; int halfWidth = image.Width / 2; int halfHeight = image.Height / 2; var resized = new Bitmap(halfWidth, halfHeight); using var graphics = Graphics.FromImage(resized); timestamps.t3 = sw.ElapsedMilliseconds; graphics.CompositingQuality = CompositingQuality.HighSpeed; graphics.InterpolationMode = InterpolationMode.HighQualityBicubic; graphics.CompositingMode = CompositingMode.SourceCopy; graphics.DrawImage(image, 0, 0, halfWidth, halfHeight); graphics.DrawImage(image, halfWidth, halfHeight, image.Width, image.Height); graphics.DrawImage(image, 0, halfHeight, halfWidth, image.Height); graphics.DrawImage(image, halfWidth, 0, image.Width, halfHeight); timestamps.t4 = sw.ElapsedMilliseconds; using var outStream = new MemoryStream(); resized.Save(outStream, ImageFormat.Jpeg); timestamps.t5 = sw.ElapsedMilliseconds; sw.Stop(); _timestamps.AddTileTimestamps(timestamps); return(new FileContentResult(outStream.ToArray(), "image/jpeg")); } catch (Exception ex) { Console.WriteLine($"{ex}"); return(StatusCode(StatusCodes.Status500InternalServerError)); } }
public void AddResizeTimestamps(TimestampDTO timestamps) { _resizeImageTimestamp.Add(timestamps); }
public void AddTileTimestamps(TimestampDTO timestamps) { _tileImageTimestamp.Add(timestamps); }