图片尺寸
protected void btnUpload_Click(object sender, EventArgs e) { int width = 0, height = 0; if (fileUpload.HasFile) { string dict = "/Content/Files/" + DateTime.Now.ToShortDateString() + "/"; string serverPath = Server.MapPath(dict); if (!System.IO.File.Exists(serverPath)) { System.IO.Directory.CreateDirectory(serverPath); string filePath = serverPath + fileUpload.FileName; fileUpload.SaveAs(filePath); getImageSize(filePath, out width, out height); if (width >= 400 || height >= 400) { literFile.Text = "上传文件尺寸必须是:400*400"; System.IO.File.Delete(filePath); } else { literFile.Text = width + ":" + height; } } } else { Response.Write("没有上传文件"); } } private void getImageSize(string filePath, out int iWidth, out int iHeight) { iWidth = iHeight = 0;
//FileStream System.Drawing.Image imgFile = System.Drawing.Image.FromFile(filePath); if (imgFile != null) { iWidth = imgFile.Width; iHeight = imgFile.Height; } imgFile.Dispose(); }
生活没有输赢,不要在乎别人如何评价你,开心就好。
QQ群:158138959