Can I use System.Drawing Via MVC Controller/View in my Razor .NET Core C# website?

  Kiến thức lập trình

I have MVC Controller and Views added to my Razor .NET Core C# web application.

It handles PayPal payments but I am thinking could I use this Controller with a View to upload and manipulate images using System.Drawing?
(System.Drawing does not work in Razor Core website)

I have many examples in MVC I have created to manipulate images. Just can’t seem to get anything working for my new Razor Core .NET C# website.

To give more insight into my problem I have included the code I am working on below in my website that shows where I ran into the need for Image manipulation. The code uploads a file/image no problem. It is still barebones with no validation but any attempt to manipulate the file as Image before upload fails.

I was thinking if I have an MVC Controller and a View inside of Razor applications, that it would allow all the options that System.Drawing provides. I have spent some considerable time browsing thru existing answers on SO, my favorite problem solver.

namespace DaBamba.Pages.YourDances
    public class UploadFileModel : PageModel
        private readonly Microsoft.AspNetCore.Hosting.IWebHostEnvironment _environment;
        public UploadFileModel(Microsoft.AspNetCore.Hosting.IWebHostEnvironment environment)
            _environment = environment;
        public IFormFile Upload { get; set; }
        public async Task OnPostAsync()

            var file = "C:\inetpub\wwwroot\DaBamba\wwwroot\images\DanceImages\" + Upload.FileName;

            using var fileStream = new FileStream(file, FileMode.Create);
            //RESIZE IMAGE HERE

            await Upload.CopyToAsync(fileStream);