mirror of https://github.com/ivanch/tcc.git
61 lines
1.7 KiB
C#
61 lines
1.7 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);
|
|
mstream.Close();
|
|
|
|
var blurredImageStream = new MemoryStream();
|
|
result.Write(blurredImageStream);
|
|
blurredImageStream.Position = 0;
|
|
|
|
return File(blurredImageStream, "image/png");
|
|
}
|
|
|
|
[HttpGet("load-small-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;
|
|
|
|
ImageService.SaveImage(mstream);
|
|
mstream.Close();
|
|
|
|
return Ok();
|
|
}
|
|
}
|
|
}
|