C# 需要访问system.drawing.image以获取图像尺寸
我需要得到作为文件上传的图像的尺寸 我试着这样做:C# 需要访问system.drawing.image以获取图像尺寸,c#,asp.net-core,asp.net-core-3.1,C#,Asp.net Core,Asp.net Core 3.1,我需要得到作为文件上传的图像的尺寸 我试着这样做: // where userFileUpload is an IFormFile: using (var fileStream = new FileStream(filePath, FileMode.Create)) { await userFileUpload.CopyToAsync(fileStream); using (var img = System.Drawing.Image.FromStream(fileStream
// where userFileUpload is an IFormFile:
using (var fileStream = new FileStream(filePath, FileMode.Create))
{
await userFileUpload.CopyToAsync(fileStream);
using (var img = System.Drawing.Image.FromStream(fileStream))
{
// TODO: Get dimensions of the image
}
}
但是我得到一个错误,说在System.Drawing中找不到“类型名称”Image
但是根据微软的文档,它应该在那里
有没有更好的方法获取图像尺寸
谢谢
但是我得到一个错误,说在System.Drawing中找不到“类型名称”Image
微软已经发布了System.Drawing.Common
作为一个NuGet。你需要先下载它
Install-Package System.Drawing.Common -Version 4.7.0
MemoryStream memStream=newmemoryStream(userFileUpload.FileBytes.ToArray());var image=System.Drawing.image.FromStream(memStream,false);