c# image.fromstream 读取jpg 宽高分辨率
时间: 2024-03-31 11:33:57 浏览: 12
你可以使用C#中的`Image.FromStream()`方法来读取JPEG图像的宽度、高度和分辨率。下面是一个示例代码:
```csharp
using System.Drawing;
using System.Drawing.Imaging;
// 读取JPEG图像的宽度、高度和分辨率
using (Stream stream = File.OpenRead("image.jpg"))
{
using (Image image = Image.FromStream(stream, false, false))
{
int width = image.Width;
int height = image.Height;
int resolutionX = (int)image.HorizontalResolution;
int resolutionY = (int)image.VerticalResolution;
// 打印结果
Console.WriteLine("Width: {0}, Height: {1}, Resolution: {2} x {3}",
width, height, resolutionX, resolutionY);
}
}
```
在这个示例中,我们使用`Image.FromStream()`方法从文件中读取JPEG图像,并获取它的宽度、高度和分辨率。请注意,我们还需要引用`System.Drawing`和`System.Drawing.Imaging`命名空间才能使用这些类和方法。