2023-08-16 18:58:01 +00:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using TCC.Services;
|
2023-08-16 18:40:27 +00:00
|
|
|
|
|
2023-08-16 18:58:01 +00:00
|
|
|
|
namespace TCC.Controllers
|
2023-08-16 18:40:27 +00:00
|
|
|
|
{
|
|
|
|
|
[ApiController]
|
2023-08-20 20:21:58 +00:00
|
|
|
|
[Route("image")]
|
2023-08-16 18:40:27 +00:00
|
|
|
|
public class ImageController : ControllerBase
|
|
|
|
|
{
|
2023-08-16 18:58:01 +00:00
|
|
|
|
private ImageService ImageService { get; set; }
|
2023-08-18 18:14:53 +00:00
|
|
|
|
public byte[] ImageData { get; set; }
|
2023-08-16 18:58:01 +00:00
|
|
|
|
|
|
|
|
|
public ImageController(ImageService imageService)
|
|
|
|
|
{
|
|
|
|
|
this.ImageService = imageService;
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-16 18:40:27 +00:00
|
|
|
|
[HttpPost("blur")]
|
2023-08-20 20:21:58 +00:00
|
|
|
|
public async Task<IActionResult> BlurImage([FromQuery] int radius)
|
2023-08-16 18:40:27 +00:00
|
|
|
|
{
|
|
|
|
|
MemoryStream mstream = new MemoryStream();
|
|
|
|
|
await HttpContext.Request.Body.CopyToAsync(mstream);
|
2023-08-16 18:58:01 +00:00
|
|
|
|
mstream.Position = 0;
|
2023-08-16 18:40:27 +00:00
|
|
|
|
|
2023-08-20 20:21:58 +00:00
|
|
|
|
var result = ImageService.BoxBlurImage(mstream, radius);
|
2023-09-11 02:14:21 +00:00
|
|
|
|
mstream.Close();
|
2023-08-16 18:40:27 +00:00
|
|
|
|
|
|
|
|
|
var blurredImageStream = new MemoryStream();
|
2023-08-16 18:58:01 +00:00
|
|
|
|
result.Write(blurredImageStream);
|
2023-08-16 18:40:27 +00:00
|
|
|
|
blurredImageStream.Position = 0;
|
|
|
|
|
|
|
|
|
|
return File(blurredImageStream, "image/png");
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-11 02:14:21 +00:00
|
|
|
|
[HttpGet("load-small-image")]
|
2023-08-20 20:21:58 +00:00
|
|
|
|
public async Task<IActionResult> GetSimpleImage()
|
|
|
|
|
{
|
2023-09-11 02:14:21 +00:00
|
|
|
|
return File(ImageService.GetSimpleImage(), "image/png");
|
2023-08-20 20:21:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet("load-big-image")]
|
|
|
|
|
public async Task<IActionResult> GetBigImage()
|
|
|
|
|
{
|
2023-09-11 02:14:21 +00:00
|
|
|
|
return File(ImageService.GetBigImage(), "image/png");
|
2023-08-20 20:21:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost("save-big-image")]
|
|
|
|
|
public async Task<IActionResult> SaveBigImage()
|
|
|
|
|
{
|
|
|
|
|
MemoryStream mstream = new MemoryStream();
|
|
|
|
|
await HttpContext.Request.Body.CopyToAsync(mstream);
|
|
|
|
|
mstream.Position = 0;
|
2023-09-11 02:14:21 +00:00
|
|
|
|
mstream.Close();
|
2023-08-20 20:21:58 +00:00
|
|
|
|
|
|
|
|
|
return Ok();
|
|
|
|
|
}
|
2023-08-16 18:40:27 +00:00
|
|
|
|
}
|
|
|
|
|
}
|