生成缩略图(不失真)

       #region 获取缩略图
        /// 
        /// 获取缩略图
        /// 
        /// 要做缩略图的图片路径
        /// 保存缩略图的路径
        /// 是否成功
        public static bool makeListImage(string imgPath, string savePaty)
        {
            try
            {
                System.Drawing.Image img = System.Drawing.Image.FromFile(imgPath);
                Graphics g = Graphics.FromImage(img);
                Font font = new Font("宋体", 14);
                Brush brush = Brushes.Black;
                g.DrawString("100wx.com", font, brush, 3, 3);
                //创建委托
                System.Drawing.Image.GetThumbnailImageAbort callback = new System.Drawing.Image.GetThumbnailImageAbort(gett);
               //生成图片的大小
                img = img.GetThumbnailImage(45, 45, callback, new IntPtr());
                img.Save(savePaty, System.Drawing.Imaging.ImageFormat.Jpeg);
                g.Dispose();
                img.Dispose();
                //PPD1aGlm
            }
            catch { return false; }
            return true;
        }
        public static bool gett()
        {
            return true;
        }
        #endregion

你可能感兴趣的:(ASP.NET)