ImageTool.cs

(开头部分) 37KB

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

/************************************************************
 * Copyright (C) Corporation. All rights reserved.
 * 
 * Author      :  lihaitao 
 * Email        : lhtzbj12@126.com
 * Create Date  :  2016-8-15
 * Description  : 图片处理工具,包括固定宽高、限制宽高、限制长边、文字水印(透明)、图片水印(透明、任意角度旋转)
 * 
 *          
 * Revision History:
 *      Date         Author               Description
 *      2016-8-15   lihaitao               create
 *  
*************************************************************/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.IO;
using System.Runtime.InteropServices;

namespace SDLight.Util
{
    public partial class ImageTool
    {
        #region 变量
        //优化良好的图片每个像素平均占用文件大小,经验值,可根据需要修改
        private static readonly double sizePerPx = 0.18;
        #endregion
        #region 生成高质量缩略图、优化图片      
        /// <summary>
        /// 生成高质量缩略图(固定宽高),不一定保持原宽高比
        /// </summary>
        /// <param name="destPath">目标保存路径</param>
        /// <param name="srcPath">源文件路径</param>
        /// <param name="width">生成缩略图的宽度,设置为0,则与源图比处理</param>
        /// <param name="height">生成缩略图的高度,设置为0,则与源图等比例处理</param>
        /// <param name="quality">1~100整数,无效值则取默认值95</param>
        /// <param name="mimeType">如 image/jpeg</param>    
        public bool GetThumbnailImage(string destPath, string srcPath, int destWidth, int destHeight, int quality, out string error, string mimeType = "image/jpeg")
        {
            bool retVal = false;
            error = string.Empty;
            //宽高不能小于0
            if (destWidth < 0 || destHeight < 0)
            {
                error = "目标宽高不能小于0";
                return retVal;
            }
            //宽高不能同时为0
            if (destWidth == 0 && destHeight == 0)
            {
                error = "目标宽高不能同时为0";
                return retVal;
            }            
            Image srcImage = null;
后面还有 735 行代码,解锁后查看完整代码

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

AI 解读

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

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