English 中文(简体)
能够使用系统。 摘自VC 页: 1
原标题:Can I use System.Drawing Via MVC Controller/View in my Razor .NET Core C# website?

我有MVC主计长和我的Razak先生的意见。 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)

我在MVC中树立了许多榜样来操纵图像。 似乎没有人为我的新的核心工作。 NET C# website。

为了更深入地了解我的问题,我把我正在以下网站上工作的守则列入我的网站,其中显示了我对篡改形象的需要。 密码上载了档案/无问题。 它仍然没有被证实,而是试图在卸载之前操纵档案。

我想,如果我有MVC主计长,并在Rzakor的申请内有观点,它将允许该系统的所有选择。 引资。 我花了相当长的时间,在我有利的问题解决者——SO问题上,用了现有的答案。

namespace DaBamba.Pages.YourDances
{
    public class UploadFileModel : PageModel
    {
        private readonly Microsoft.AspNetCore.Hosting.IWebHostEnvironment _environment;
        public UploadFileModel(Microsoft.AspNetCore.Hosting.IWebHostEnvironment environment)
        {
            _environment = environment;
        }
        [BindProperty]
        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);
        }
    }
}
问题回答

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)

Yeah,如评论所述,在ASP.NET中,你是正确的。 核心或微粒页应用,可直接使用系统。 由于平台的兼容性限制,因此难以做到。 此外,由于系统限制和安全考虑,没有建议进行图像处理。

相反,你可以尝试很少其他办法,以实现图像操纵。

例如,您可使用<代码>System.Drawing.Common。 NuGet式包裹或可使用图像Sharp图书馆进行图像处理。 NET 核心应用。

Let s have a look how you can implement that:

You can, install System.Drawing.Common library.

“在座的影像描述”/</a

在安装成功后,你可以使用图象、比图和图象等课程进行基本图像操作。

例如:

using (var image = Image.FromStream(Upload.OpenReadStream()))
{
    using (var resizedImage = new Bitmap(image, new Size(newWidth, newHeight)))
    using (var stream = new MemoryStream())
    {
        resizedImage.Save(stream, ImageFormat.Jpeg);
        await stream.CopyToAsync(fileStream);
    }
}

或者,你甚至可以尝试<代码>Imagesharp Library。 在这种情况下,你可以做如下工作:

“在座的影像描述”/</a

In case of ImageSharp, first of all, you should open the uploaded image using the ImageSharp library, After that, you can resize the image using its width and height attribute. Finally, you can save the resized image to the file stream.

让我们在实践中审视我们如何能够做到:

            var file = Path.Combine(_environment.WebRootPath, "images", "DanceImages", Upload.FileName);

            using (var fileStream = new FileStream(file, FileMode.Create))
            {
               
                using (var image = Image.Load(Upload.OpenReadStream()))
                {
                   
                    var width = 300;
                    var height = 200;
                    image.Mutate(x => x.Resize(new ResizeOptions
                    {
                        Size = new Size(width, height),
                        Mode = ResizeMode.Max
                    }));

                    
                    image.Save(fileStream, new JpegEncoder());
                }
            }

<>说明: 你可以尝试其他办法,以达到你的要求。 此外,您可以





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签