相关疑难解决方法(0)

如何在C#中验证图像文件格式

有没有人知道脚本来验证给定图像的文件格式是什么.目前我正在填充图像对象,查看它的高度,宽度和分辨率.我没有看到解释文件格式的此对象的任何特定属性.

我想查看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;

    }
Run Code Online (Sandbox Code Playgroud)

提前致谢

c# graphics image

3
推荐指数
1
解决办法
4760
查看次数

标签 统计

c# ×1

graphics ×1

image ×1