tcc/ASP.NET/Controllers/ImageController.cs

69 lines
1.9 KiB
C#
Raw Normal View History

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-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-08-20 20:21:58 +00:00
[HttpGet("load-image")]
public async Task<IActionResult> GetSimpleImage()
{
var result = ImageService.GetSimpleImage();
var imageStream = new MemoryStream();
result.Write(imageStream);
imageStream.Position = 0;
return File(imageStream, "image/png");
}
[HttpGet("load-big-image")]
public async Task<IActionResult> GetBigImage()
{
var result = ImageService.GetBigImage();
var imageStream = new MemoryStream();
result.Write(imageStream);
imageStream.Position = 0;
return File(imageStream, "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();
}
2023-08-16 18:40:27 +00:00
}
}