Beispiel #1
0
        public static string Process(FileInfo fiold, string waterText)
        {
            try
            {
                using (var fs = fiold.Open(FileMode.Open, FileAccess.Read))
                {
                    System.Drawing.Image img = System.Drawing.Image.FromStream(fs);
                }
            }
            catch (Exception ex)
            {
                return("");
            }

            LogerHelper.Debug("saveFileLogs", "后缀名:" + fiold.Extension + ":::文件名:" + fiold.Name);
            try
            {
                if (!string.IsNullOrWhiteSpace(waterText))
                {
                    string oldpath = fiold.FullName;
                    string newpath = fiold.FullName;
                    AttachmentCenter.UtilsHelp.Watermark.AddWaterText(fiold.FullName, waterText, newpath, 118, 18);
                    LogerHelper.Debug("saveFileLogs", ":::水印文件名:" + fiold.Name);
                }
            }
            catch (Exception e)
            {
                LogerHelper.Error(e.Message, "FileProcess", e);
                throw new Exception("水印添加失败!" + e.Message);
            }
            try
            {
                var             tName  = fiold.FullName.Insert(fiold.FullName.LastIndexOf('.'), "Thumbnail");
                ThumbnailConfig config = Controllers.ConfigHelper.GetSetting <ThumbnailConfig>("Thumbnail");
                switch (config.ThumbnailType)
                {
                case 0:
                {
                    Thumbnail.MakeSquareImage(fiold.FullName, tName, (int)config.MaxLength);
                    break;
                }

                case 1:
                {
                    Thumbnail.MakeThumbnailImage(fiold.FullName, tName, config.MaxLength, config.MaxLength);
                    break;
                }
                }
                return(new FileInfo(tName).Name);
            }
            catch (Exception ex)
            {
                LogerHelper.Error(ex.Message, "FileProcess", ex);
            }
            return("");
        }
Beispiel #2
0
        /// <summary>
        /// 保存图片
        /// </summary>
        /// <param name="image">Image 对象</param>
        /// <param name="savePath">保存路径</param>
        /// <param name="ici">指定格式的编解码参数</param>
        private static void SaveImage(Image image, string savePath, ImageCodecInfo ici)
        {
            ThumbnailConfig config = Controllers.ConfigHelper.GetSetting <ThumbnailConfig>("Thumbnail");
            // 设置 原图片 对象的 EncoderParameters 对象
            EncoderParameters parameters = new EncoderParameters(1);

            parameters.Param[0] = new EncoderParameter(Encoder.Quality, ((long)config.Compress));
            image.Save(savePath, ici, parameters);
            parameters.Dispose();
        }