zoukankan      html  css  js  c++  java
  • 图片尺寸

      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(); }
  • 相关阅读:
    linux 时间设置
    linux
    linux 关闭防火墙
    GIS-008-ArcGIS JS API 全图
    GIS-007-Terrain跨域访问
    GIS-006-ArcGIS API 空间关系
    Python 中文乱码
    GIS-005-Dojo & jQuery 事件处理
    GIS-004-Cesium版权信息隐藏
    GIS-003-在线地图下载及应用
  • 原文地址:https://www.cnblogs.com/zjflove/p/3590638.html
Copyright © 2011-2022 走看看