在不加载图像的情况下可靠地获取.NET中的图像尺寸,可以使用以下方法:
using System.Drawing;
string imagePath = "path/to/image.jpg";
Image image = Image.FromFile(imagePath);
int width = image.Width;
int height = image.Height;
using System.IO;
using System.Drawing;
string imagePath = "path/to/image.jpg";
byte[] imageData = File.ReadAllBytes(imagePath);
using MemoryStream ms = new MemoryStream(imageData);
Image image = Image.FromStream(ms);
int width = image.Width;
int height = image.Height;
using System.IO;
using System.Drawing;
string imagePath = "path/to/image.jpg";
byte[] imageData = File.ReadAllBytes(imagePath);
using MemoryStream ms = new MemoryStream(imageData);
Bitmap bitmap = new Bitmap(ms);
int width = bitmap.Width;
int height = bitmap.Height;
以上方法均可在不加载图像的情况下可靠地获取.NET中的图像尺寸。
领取专属 10元无门槛券
手把手带您无忧上云