App_Code/CommonComponent/PictureSlightly.cs

(开头部分) 3KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Drawing;

namespace EnterpriseNET.CommonComponent
{
    public class PictureSlightly
    {
        //public PictureSlightly()
        //{
            //
            // TODO: Add constructor logic here
            //
        //}

        /// <summary>
        /// 生成缩略图
        /// </summary>
        /// <param name="SourceImage">源图路径(含图片,物理路径)</param>
        /// <param name="ImageMapth">缩略图路径(含图片,物理路径)</param>
        /// <param name="width">缩略图宽</param>
        /// <param name="height">缩略图高</param>
        //public static void MakeImage(string sourceImage, string imageMapth, int width, int height, string mode)
        public void MakeImage(string sourceImage, string imageMapth, int width, int height, string mode)
        {
            System.Drawing.Image MyImage = System.Drawing.Image.FromFile(sourceImage);
            int towidth = width;
            int toheight = height;
            int x = 0, y = 0;
            int ow = MyImage.Width;
            int oh = MyImage.Height;
            switch (mode)
            {
                case "hw": break;       //指定高宽缩放(可能变形)
                case "w": toheight = MyImage.Height * width / MyImage.Width; break;     //指定宽,高按比例
                case "h": towidth = MyImage.Width * height / MyImage.Height; break;     //指定高,宽按比例
                case "cut":             //指定高宽裁减(不变形)
                    if ((double)MyImage.Width / (double)MyImage.Height > (double)towidth / (double)toheight)
                    {
                        oh = MyImage.Height;
                        ow = MyImage.Width * towidth / toheight;
                        y = 0;
                        x = (MyImage.Width - ow) / 2;
                    }
                    else
                    {
                        ow = MyImage.Width;
                        oh = MyImage.Height * height / toheight;
                        x = 0;
                        y = (MyImage.Height - oh) / 2;
                    }; break;
                default: break;
            }
后面还有 34 行代码,购买后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明

AI 解读

登录后可用,每次 10 积分,解读结果公开显示在下面。

还没有人解读过这个文件。