Esempio n. 1
0
        /// <summary>
        /// 根据原始图片名称和缩略图后缀(_s或_m等),获取缩略图名称
        /// </summary>
        /// <param name="srcPath"></param>
        /// <param name="suffix">请勿添加下划线,系统会自动添加</param>
        /// <returns></returns>
        public static String GetThumbPath(Object srcPath, String suffix)
        {
            if (srcPath == null)
            {
                return("");
            }
            String path = srcPath.ToString();

            if (strUtil.IsNullOrEmpty(path))
            {
                return("");
            }

            String ext            = Path.GetExtension(path);
            String pathWithoutExt = strUtil.TrimEnd(path, ext);

            if (suffix.StartsWith("_") == false)
            {
                suffix = "_" + suffix;
            }

            foreach (KeyValuePair <String, ThumbInfo> kv in ThumbConfig.GetPhotoConfig())
            {
                pathWithoutExt = strUtil.TrimEnd(pathWithoutExt, "_" + kv.Key);
            }

            return(pathWithoutExt + suffix + ext);
        }
Esempio n. 2
0
        /// <summary>
        /// 将图片拷贝到上传目录中,并生成中、小缩略图
        /// </summary>
        /// <param name="oPath">原始相对路径</param>
        /// <returns>返回图片名称,包括所在文件夹,比如 2009/9/28/1530703343314547.jpg</returns>
        public static string CopyToUploadPath(String oPath)
        {
            oPath = PathHelper.Map(oPath);

            // 需要保存的路径
            String shortPath  = Img.GetPhotoName(Path.GetExtension(oPath));
            String targetPath = PathHelper.Map(strUtil.Join(sys.Path.DiskPhoto, shortPath));

            logger.Info("copy pic. oPath=" + oPath + ", target=" + targetPath);

            // 1) 复制原图
            file.Copy(oPath, targetPath);

            Dictionary <String, ThumbInfo> thumbConfigMap = ThumbConfig.GetPhotoConfig();

            foreach (KeyValuePair <String, ThumbInfo> kv in thumbConfigMap)
            {
                String sPath = Img.GetThumbPath(targetPath, kv.Key);
                Img.SaveThumbnail(oPath, sPath, kv.Value.Width, kv.Value.Height, kv.Value.Mode);
            }

            return(shortPath);
        }
Esempio n. 3
0
 /// <summary>
 /// 删除图片以及缩略图。如果图片不存在,则忽略
 /// </summary>
 /// <param name="srcPath">相对网址</param>
 public static void DeleteImgAndThumb(String srcPath)
 {
     DeleteImgAndThumb(srcPath, ThumbConfig.GetPhotoConfig());
 }