Exemple #1
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);
        }