SkyeBoniwell
SkyeBoniwell

Reputation: 7122

Need to access system.drawing.image in order to get image dimensions

I need to get the dimensions of an image that is uploaded as an IFormFile.

I am trying to do it like this:

// 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
    }
}

But I am getting an error saying 'the type name 'Image' could not be found in System.Drawing.

But according to this Microsoft Doc, it should be there.

https://learn.microsoft.com/en-us/dotnet/api/system.drawing.image.fromstream?view=dotnet-plat-ext-3.1

Is there a better way of getting the image dimensions?

Thanks!

Upvotes: 0

Views: 241

Answers (1)

mj1313
mj1313

Reputation: 8479

But I am getting an error saying 'the type name 'Image' could not be found in System.Drawing.

Microsoft has released System.Drawing.Common as a NuGet. You need to download it first.

Install-Package System.Drawing.Common -Version 4.7.0

Upvotes: 1

Related Questions