闫振

博客园 首页 联系 订阅 管理

ASP.NET中获取图片的尺寸

public void GetImageSize(string FullFilePath) {//参数为图片文件的绝对路径
        System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(FullFilePath);
        int width = bmp.Width;   //
        int height = bmp.Height; //
    }

获取上传的图片的尺寸

public void GetUploadImageSize() {
        //txt_Load为上传控件对象
        System.Drawing.Image bmp = System.Drawing.Image.FromStream(txt_Load.PostedFile.InputStream);
        int width = bmp.Width;   //
        int height = bmp.Height; //
    }

JS里获取图片的尺寸

//有些浏览器获取不到本地的图片(安全设置)
        var getImageSize = function () {
            var image = new Image();
            image.src = document.getElementById("test_img").src;
            var width = image.width;     //
            var height = image.height;   //
        }