【发布时间】:2011-01-04 10:48:04
【问题描述】:
有谁知道验证给定图像的文件格式的脚本。目前我正在填充一个图像对象,查看它的高度、宽度和分辨率。我没有看到此对象的任何特定属性可以解释文件格式。
我想检查 jpg、AI、PSD、High Jes Jpg、Bitmap 和 Tiff。
这是我当前的脚本:
protected bool IsValidImage(HttpPostedFileBase file, string fileName) {
//verify that the image is no more than 648 wide and 648 pixels tall
Image imgPhoto = Image.FromStream(file.InputStream);
if (imgPhoto.Width > 648)
return false;
if (imgPhoto.Height > 648)
return false;
if (imgPhoto.HorizontalResolution != 72 || imgPhoto.VerticalResolution != 72)
return false;
return true;
}
提前致谢
【问题讨论】:
-
好吧,如果你有文件名,为什么不检查扩展名?
-
Image 类将无法处理 AI 或 PSD...
-
@Thomas - 我相信如果您安装了 AI 或 PSD 编解码器,那么 Image 将能够使用 ImageFormat GUID 告诉您。