App_Code/CompressPic.cs

(开头部分) 2KB

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

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

/// <summary>
/// CompressPic 的摘要说明
/// </summary>
public class CompressPic
{
    /// <summary>
    /// 压缩指定尺寸的封面
    /// </summary>
    /// <param name="ofile">旧文件</param>
    /// <param name="nfile">新文件</param>
    /// <returns></returns>
    public bool Compress(string ofile, string nfile)
    {
        try
        {
            System.Drawing.Image img = System.Drawing.Image.FromFile(ofile);
            System.Drawing.Imaging.ImageFormat thisFormat = img.RawFormat;
            int width = img.Width;
            int height = img.Height;
            if (width > 198)
            {
                height = height * (198 * 1000 / width) / 1000;
                width = 198;
            }
            else if (height > 287)
            {
                width = width * (287 * 1000 / height) / 1000;
                height = 287;
            }
            Size newSize = new Size(width, height);
            Bitmap outBmp = new Bitmap(newSize.Width, newSize.Height);
            Graphics g = Graphics.FromImage(outBmp);
            g.CompositingQuality = CompositingQuality.HighQuality;
            g.SmoothingMode = SmoothingMode.HighQuality;
            g.InterpolationMode = InterpolationMode.HighQualityBicubic;
            g.DrawImage(img, new Rectangle(0, 0, newSize.Width, newSize.Height), 0, 0, img.Width, img.Height, GraphicsUnit.Pixel);
            g.Dispose();
            EncoderParameters encoderParams = new EncoderParameters();
            long[] quality = new long[1];
            quality[0] = 100;
            EncoderParameter encoderParam = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, quality);
            encoderParams.Param[0] = encoderParam;
            ImageCodecInfo[] arrayICI = ImageCodecInfo.GetImageEncoders();
            ImageCodecInfo jpegICI = null;
            for (int x = 0; x < arrayICI.Length; x++)
                if (arrayICI[x].FormatDescription.Equals("JPEG"))
                {
后面还有 14 行代码,解锁后查看完整代码

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

AI 解读 AI

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

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