tcc/ASP.NET/Controllers/ImageController.cs

69 lines
2.0 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()
{
//var result = ImageService.GetSimpleImage();
var result = System.IO.File.ReadAllBytes("simpleimage.png");
var imageStream = new byte[result.Length];
result.CopyTo(imageStream, 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();
}
}
}