tcc/ASP.NET/Controllers/ImageController.cs

57 lines
1.6 KiB
C#

using Microsoft.AspNetCore.Mvc;
using TCC.Services;
namespace TCC.Controllers
{
[ApiController]
[Route("image")]
public class ImageController : ControllerBase
{
private ImageService ImageService { get; set; }
public byte[] ImageData { get; set; }
public ImageController(ImageService imageService)
{
this.ImageService = imageService;
}
[HttpPost("blur")]
public async Task<IActionResult> BlurImage([FromQuery] int radius)
{
MemoryStream mstream = new MemoryStream();
await HttpContext.Request.Body.CopyToAsync(mstream);
mstream.Position = 0;
var result = ImageService.BoxBlurImage(mstream, radius);
var blurredImageStream = new MemoryStream();
result.Write(blurredImageStream);
blurredImageStream.Position = 0;
return File(blurredImageStream, "image/png");
}
[HttpGet("load-image")]
public async Task<IActionResult> GetSimpleImage()
{
return File(ImageService.GetSimpleImage(), "image/png");
}
[HttpGet("load-big-image")]
public async Task<IActionResult> GetBigImage()
{
return File(ImageService.GetBigImage(), "image/png");
}
[HttpPost("save-big-image")]
public async Task<IActionResult> SaveBigImage()
{
MemoryStream mstream = new MemoryStream();
await HttpContext.Request.Body.CopyToAsync(mstream);
mstream.Position = 0;
return Ok();
}
}
}