需要访问 system.drawing.image 以获得图像尺寸
Need to access system.drawing.image in order to get image dimensions
我需要获取作为 IFormFile 上传的图像的尺寸。
我正在尝试这样做:
// 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'。
但根据这个 Microsoft Doc,它应该在那里。
https://docs.microsoft.com/en-us/dotnet/api/system.drawing.image.fromstream?view=dotnet-plat-ext-3.1
是否有更好的获取图像尺寸的方法?
谢谢!
But I am getting an error saying 'the type name 'Image' could not be found in System.Drawing.
Microsoft 已将 System.Drawing.Common
作为 NuGet 发布。您需要先下载它。
Install-Package System.Drawing.Common -Version 4.7.0
我需要获取作为 IFormFile 上传的图像的尺寸。
我正在尝试这样做:
// 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'。
但根据这个 Microsoft Doc,它应该在那里。
https://docs.microsoft.com/en-us/dotnet/api/system.drawing.image.fromstream?view=dotnet-plat-ext-3.1
是否有更好的获取图像尺寸的方法?
谢谢!
But I am getting an error saying 'the type name 'Image' could not be found in System.Drawing.
Microsoft 已将 System.Drawing.Common
作为 NuGet 发布。您需要先下载它。
Install-Package System.Drawing.Common -Version 4.7.0