获得图片的宽和高 - GetImageWidthHeight

2017-02-26 15:33:19  访问(1417) 赞(0) 踩(0)

  • 
            /// <summary>
            /// 获得图片的宽和高 - GetImageWidthHeight
            /// </summary>
            /// <param name="imageFileName"></param>
            /// <returns></returns>
            public static WidthHeightClass GetImageWidthHeight(string imageFileName)
            {
                if (!File.Exists(imageFileName))
                    throw new Exception
                    (
                        "方法:"
                        + MethodBase.GetCurrentMethod().ReflectedType.FullName
                        + " "
                        + MethodBase.GetCurrentMethod().ToString()
                        + " 发生异常:" + imageFileName + " 文件不存在");
    
                System.Drawing.Image img = System.Drawing.Image.FromFile(imageFileName);
    
                return new WidthHeightClass(img.Width, img.Height);
    
            }
    

  • using System;
    using System.Collections.Generic;
    using System.Text;
    
    namespace SlowX.Functions.Classes
    {
        /// <summary>
        /// 宽和高的结构 - WidthHeightClass + 
        /// </summary>
        [Serializable]
        public class WidthHeightClass
        {
            /// <summary>
            /// 宽和高的结构
            /// </summary>
            public WidthHeightClass()
            {
    
            }
    
            /// <summary>
            /// 宽和高的结构
            /// </summary>
            /// <param name="_Width"></param>
            /// <param name="_Height"></param>
            public WidthHeightClass(int _Width, int _Height)
            {
                m_Width = _Width;
    
                m_Height = _Height;
            }
    
            /// <summary>
            /// 宽
            /// </summary>
            protected int m_Width = 0;
    
            /// <summary>
            /// 宽
            /// </summary>
            public int Width
            {
                get
                {
                    return m_Width;
                }
                set
                {
                    m_Width = value;
                }
            }
    
            /// <summary>
            /// 高
            /// </summary>
            protected int m_Height = 0;
    
            /// <summary>
            /// 高
            /// </summary>
            public int Height
            {
                get
                {
                    return m_Height;
                }
                set
                {
                    m_Height = value;
                }
            }
        }
    }
    
    

标签:获得图片的宽和高 - GetImageWidthHeight 

上一条:

下一条:


 

相关评论

评论加载中……
 

发表评论

类型:
内容:
  (Alt+Enter)