.NET 生成生成缩略图

 /// <summary>
        /// 生成缩略图
        /// </summary>
        /// <param name="FromImagePath">源图路径(绝对路径)</param>
        /// <param name="ToImagePath">缩略图路径(绝对路径)</param>
        /// <param name="MaxWidth">最大宽度</param>
        /// <param name="MaxHeight">最大高度</param>
        public static void CreatePic(string FromImagePath, string ToImagePath, double MaxWidth, double MaxHeight)
        {
            Bitmap tmp = null;
            Graphics g = null;
            //double Max_width = 110, Max_height = 110;//假设最大宽度以及最大高度
            int Width = 0;//框条和卡纸的宽度
            int Height = 0;//框条和卡纸的高度
            double wmp = 1, hmp = 1, default_pparm = 1;//默认宽的比例,默认高对应的比例,最大宽度比例,最大高度比例,默认实际比例,最大实际比例
            System.Drawing.Image imgPic = null;//画芯
            imgPic = System.Drawing.Image.FromFile(FromImagePath);
            Width = imgPic.Width;
            Height = imgPic.Height;
            wmp = MaxWidth / Width;//最大宽度比例
            hmp = MaxHeight / Height;//最大高度比例
            default_pparm = wmp < hmp ? wmp : hmp;//默认实际比例


            if (default_pparm > 1)
            {
                default_pparm = 1;
            }
            Width = (int)(Width * default_pparm);
            Height = (int)(Height * default_pparm);

            tmp = new Bitmap((int)(Width), (int)(Height));//最大的容器
            g = Graphics.FromImage(tmp);
            //g.FillRectangle(new SolidBrush(Color.White), new Rectangle(0, 0, tmp.Width, tmp.Height));
            Rectangle Boxs = new Rectangle(0, 0, imgPic.Width, imgPic.Height);
            Rectangle Boxd = new Rectangle(0, 0,
                                           (int)(Width), (int)(Height));//算图的起点
            g.DrawImage(imgPic, Boxd, Boxs, GraphicsUnit.Pixel);
            tmp.Save(ToImagePath, ImageFormat.Jpeg);
        }

 

转载于:https://www.cnblogs.com/Xanthus/p/9589610.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值