首页 > 其他 > 详细

图片尺寸

时间:2014-03-10 03:07:46      阅读:467      评论:0      收藏:0      [点我收藏+]
bubuko.com,布布扣
  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(); }
bubuko.com,布布扣

图片尺寸,布布扣,bubuko.com

图片尺寸

原文:http://www.cnblogs.com/zjflove/p/3590638.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!