zoukankan      html  css  js  c++  java
  • 一个缩略图的类

        public class GetThumbnailImg
        {
            /// <summary>
            /// 读取图片的缩略图
            /// </summary>
            /// <param name="PicPath">源图片的路径</param>
            /// <param name="PicTemp">生成缩略图的目录</param>
            /// <param name="Width">生成缩略图的宽</param>
            /// <param name="Height">生成缩略图的高</param>
            /// <returns>生成成功则返回路径,否则返回""</returns>
            public static string GetThumbnailPic(string PicPath, string PicTemp, int Width, int Height)
            {
                System.Drawing.Bitmap Bitmap = new System.Drawing.Bitmap(PicPath);
                if (Bitmap.Width > Width)
                {
                    Height = Bitmap.Height * Width / Bitmap.Width;
                }
                else
                {
                    Width = Bitmap.Width * Height / Bitmap.Height;
                }
                var img = Bitmap.GetThumbnailImage(Width, Height, () => { return false; }, IntPtr.Zero);
                try
                {
                    img.Save(PicTemp);
                    return PicTemp;
                }
                catch
                {
                    return "";
                }
            }
        }

    调用:

                string FileName = MapPath("~/img/") + Guid.NewGuid().ToString() + System.IO.Path.GetExtension(FileUpload1.FileName);    
                FileUpload1.SaveAs(FileName);
                string TempPath = FileName.Replace(@"img", @"imgTemp");
                var Path = GYFDLL.GetThumbnailImg.GetThumbnailPic(FileName, TempPath, 200, 200);
                Image img = new Image();
                img.ImageUrl = "~/img/Temp/" + System.IO.Path.GetFileName(Path);
                this.Controls.Add(img);
  • 相关阅读:
    左偏树
    论在Windows下远程连接Ubuntu
    ZOJ 3711 Give Me Your Hand
    SGU 495. Kids and Prizes
    POJ 2151 Check the difficulty of problems
    CodeForces 148D. Bag of mice
    HDU 3631 Shortest Path
    HDU 1869 六度分离
    HDU 2544 最短路
    HDU 3584 Cube
  • 原文地址:https://www.cnblogs.com/gouyanfeng/p/3180464.html
Copyright © 2011-2022 走看看