/// <summary> ///获取FTP存放方式 /// </summary> /// <param name="path"></param> /// <param name="fileExtName"></param> /// <param name="pathFormat"></param> /// <returns></returns> private static string GetFtpPath(string path, string fileExtName, int pathFormat, UpFileEntity upfileEntity) { StringBuilder saveDir = new StringBuilder(""); //附件保存方式 0=按年/月/日存入不同目录 1=按年/月/日/存入不同目录 2=按存入不同目录 3=按文件类型存入不同目录 if (string.IsNullOrEmpty(upfileEntity.PathFormat)) { switch (pathFormat) { case 0: { if (!string.IsNullOrEmpty(path)) { saveDir.Append(path); saveDir.Append("/"); //saveDir.Append(Path.DirectorySeparatorChar); } break; } case 1: { saveDir.Append(DateTime.Now.ToString("yyyy")); saveDir.Append("/"); saveDir.Append(DateTime.Now.ToString("MM")); saveDir.Append("/"); saveDir.Append(DateTime.Now.ToString("dd")); saveDir.Append("/"); if (!string.IsNullOrEmpty(path)) { saveDir.Append(path); saveDir.Append("/"); //saveDir.Append(Path.DirectorySeparatorChar); } break; } case 2: { saveDir.Append(path); saveDir.Append("/"); //saveDir.Append(Path.DirectorySeparatorChar); break; } case 3: { saveDir.Append(fileExtName); saveDir.Append("/"); //saveDir.Append(Path.DirectorySeparatorChar); break; } default: { saveDir.Append(DateTime.Now.ToString("yyyy")); saveDir.Append("/"); saveDir.Append(DateTime.Now.ToString("MM")); saveDir.Append("/"); saveDir.Append(DateTime.Now.ToString("dd")); saveDir.Append("/"); break; } } } else { saveDir.Append(upfileEntity.PathFormat); } return(saveDir.ToString()); }
public void SubmitForm(ContentEntity moduleEntity, string keyValue, List <UpFileDTO> upFileentitys) { string strKeyWords = string.Empty; if (!iKeyWordsRespository.IsHasKeyWords(moduleEntity.WebSiteId, moduleEntity.Content, out strKeyWords)) { using (var db = new MySqlRepositoryBase().BeginTrans()) { if (!string.IsNullOrEmpty(keyValue)) { ContentEntity moduleEntityT = FindEntity(keyValue); if (moduleEntityT != null) { //验证用户站点权限 iUserRepository.VerifyUserWebsiteRole(moduleEntityT.WebSiteId); moduleEntity.WebSiteId = moduleEntityT.WebSiteId; } moduleEntity.Modify(keyValue); db.Update(moduleEntity); //添加日志 iLogRepository.WriteDbLog(true, "修改内容信息=>" + moduleEntity.FullName, Enums.DbLogType.Update, "内容管理"); } else { string mIds = moduleEntity.ColumnId; ColumnsEntity cmModel = iColumnsRepository.GetFormNoDel(mIds); if (cmModel.Type == (int)Code.Enums.ModuleType.Content || cmModel.Type == (int)Code.Enums.ModuleType.List || cmModel.Type == (int)Code.Enums.ModuleType.AdvancedList) { if (JudgmentHelp.judgmentHelp.IsNullEntity <ColumnsEntity>(cmModel) && JudgmentHelp.judgmentHelp.IsNullOrEmptyOrGuidEmpty(cmModel.Id)) { string urlAddress = @"\" + cmModel.ActionName + @"\" + moduleEntity.Id; moduleEntity.UrlAddress = urlAddress; //SubmitForm(moduleEntity, moduleEntity.Id); } } moduleEntity.Create(); db.Insert(moduleEntity); //添加日志 iLogRepository.WriteDbLog(true, "添加内容信息=>" + moduleEntity.FullName, Enums.DbLogType.Create, "内容管理"); } if (upFileentitys != null && upFileentitys.Count > 0) { upFileentitys = upFileentitys.FindAll(m => m != null); foreach (UpFileDTO upFileentity in upFileentitys) { if (upFileentity != null) { //更新上传文件表 upFileentity.Sys_WebSiteId = moduleEntity.WebSiteId; upFileentity.Sys_ParentId = keyValue; upFileentity.Sys_ModuleName = EnumHelp.enumHelp.GetDescription(Enums.UpFileModule.Contents); UpFileEntity upFileEntity = iUpFileRepository.InitUpFileEntity(upFileentity); upFileEntity.Create(); db.Insert(upFileEntity); } } } db.Commit(); } } else { throw new Exception("存在非法关键词,请检查!关键字:" + strKeyWords); } }
private static void SaveThumb(Image img, string newFileName, ImageFormat imgFormat, UpFileEntity upFileEntity) { BaseConfigInfo config = BaseConfigs.GetConfig(); string fileName = Path.GetFileName(newFileName); if (config.DistributeFileSystem == 1 && upFileEntity.DistributeFileSystem == 1) { if (!string.IsNullOrEmpty(upFileEntity.GroupName)) { byte[] contentBytes = GetByteImage(img, imgFormat); DFSProvider.CurrentDFS.UploadSlaveFile(contentBytes, upFileEntity.Mast_File_Name, upFileEntity.Prefix_Name, upFileEntity.File_Ext.Replace(".", "")); } } else { if (config.FTPEnable == 1 && upFileEntity.FTPEnable == 1) { if (FTPs.IsLocalhost(upFileEntity.FTPIdent))//区分本地或FTP { img.Save(newFileName, imgFormat); } else { string fileExt = Path.GetExtension(newFileName); string dir = Path.GetDirectoryName(config.FTPTempPath + GetFtpPath("", fileExt, config.FTPPathFormat, upFileEntity)); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } string savePath = dir + "/" + fileName; System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch(); stopwatch.Start(); img.Save(savePath, imgFormat); //存入临时文件夹 FTPs.UpLoadFile(Path.GetDirectoryName(newFileName), savePath, upFileEntity, upFileEntity.FTPIdent); //-FTP不需要传入文件名 stopwatch.Stop(); long minsecond = stopwatch.ElapsedMilliseconds; } } else { img.Save(newFileName, imgFormat); } } img.Dispose(); #region 写入备份记录-通过接口 if (upFileEntity.AttachID > 0) { fileName = fileName.ToLower().Replace(upFileEntity.File_Ext.ToLower(), ""); string[] fileNameArr = fileName.Split('!'); string[] sites; if (fileNameArr.Length > 1) { sites = fileNameArr[1].Split('_'); } else { sites = fileName.Split('_'); } if (sites.Length == 3) { if (!string.IsNullOrEmpty(config.BakClassName)) { UploadBakProvider.GetInstance(config.BakClassName).Update(upFileEntity.AttachID, sites[1] + "_" + sites[2]); } } } #endregion }
private void SaveThumb(Image img, ImageFormat imgFormat, UpFileEntity upFileEntity) { SaveThumb(img, srcFileName, imgFormat, upFileEntity); }
public static void MakeThumbnailImage(Image img, string newFileName, int maxWidth, int maxHeight, UpFileEntity upFileEntity, bool isDispose = true) { MakeThumbnailImage(img, newFileName, maxWidth, maxHeight, true, upFileEntity, isDispose); }
public static void MakeThumbnailImage(Image img, int maxWidth, int maxHeight, bool HighQutity, UpFileEntity upFileEntity, bool isDispose = true) { MakeThumbnailImage(img, null, maxWidth, maxHeight, HighQutity, upFileEntity, isDispose); }
public static void MakeThumbnailImage(HttpPostedFileBase postFile, int maxWidth, int maxHeight, bool HighQutity, UpFileEntity upFileEntity, bool isDispose = true) { MakeThumbnailImage(postFile, null, maxWidth, maxHeight, HighQutity, upFileEntity, isDispose); }
/// <summary> /// 制作缩略图-image /// </summary> /// <param name="img">原图</param> /// <param name="newFileName">新图路径</param> /// <param name="maxWidth">最大宽度</param> /// <param name="maxHeight">最大高度</param> public static void MakeThumbnailImage(Image img, string newFileName, int maxWidth, int maxHeight, bool HighQutity, UpFileEntity upFileEntity, bool isDispose = true) { Image original = img; Size _newSize = ResizeImage(original.Width, original.Height, maxWidth, maxHeight); System.Drawing.Image hb = new System.Drawing.Bitmap(_newSize.Width, _newSize.Height); //创建图片对象 System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(hb); //创建画板并加载空白图像 g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High; //设置保真模式为高度保真 g.SmoothingMode = SmoothingMode.HighQuality; g.Clear(Color.White); g.DrawImage(original, new Rectangle(0, 0, _newSize.Width, _newSize.Height), 0, 0, original.Width, original.Height, GraphicsUnit.Pixel);//开始画图 #region 加入FTP|分布式-vebin.h:2012.12.12 if (!string.IsNullOrEmpty(newFileName)) { SaveThumb(hb, newFileName, GetFormat(newFileName), upFileEntity); } else { SaveThumb(hb, upFileEntity.Mast_File_Name.Replace(upFileEntity.File_Ext, upFileEntity.Prefix_Name + upFileEntity.File_Ext), GetFormat(upFileEntity.Mast_File_Name), upFileEntity); } #endregion //hb.Save(newFileName, GetFormat("jpg")); g.Dispose(); //hb.Dispose(); if (isDispose) { original.Dispose(); } }
public static void MakeThumbnailImage(HttpPostedFileBase postFile, string newFileName, int maxWidth, int maxHeight, UpFileEntity upFileEntity, bool isDispose = true) { MakeThumbnailImage(postFile, newFileName, maxWidth, maxHeight, true, upFileEntity, isDispose); }
/// <summary> /// 制作缩略图-postfile /// </summary> /// <param name="postFile"></param> /// <param name="newFileName"></param> /// <param name="maxWidth"></param> /// <param name="maxHeight"></param> /// <param name="HighQutity"></param> /// <param name="upFileEntity"></param> public static void MakeThumbnailImage(HttpPostedFileBase postFile, string newFileName, int maxWidth, int maxHeight, bool HighQutity, UpFileEntity upFileEntity, bool isDispose = true) { Image img = Image.FromStream(postFile.InputStream); MakeThumbnailImage(img, newFileName, maxWidth, maxHeight, HighQutity, upFileEntity, isDispose); //img.Dispose(); }
public static void MakeThumbnailImage(string fileName, int maxWidth, int maxHeight, UpFileEntity upFileEntity, bool isDispose = true) { MakeThumbnailImage(fileName, null, maxWidth, maxHeight, upFileEntity, isDispose); }
/// <summary> /// 制作小正方形 /// </summary> /// <param name="fileName">原图的文件路径</param> /// <param name="newFileName">新地址</param> /// <param name="newSize">长度或宽度</param> public static void MakeSquareImage(string fileName, string newFileName, int newSize, UpFileEntity upFileEntity) { Image image = Image.FromFile(fileName); int i = 0; int width = image.Width; int height = image.Height; if (width > height) { i = height; } else { i = width; } Bitmap b = new Bitmap(newSize, newSize); try { Graphics g = Graphics.FromImage(b); g.InterpolationMode = InterpolationMode.High; g.SmoothingMode = SmoothingMode.HighQuality; //清除整个绘图面并以透明背景色填充 g.Clear(Color.Transparent); if (width < height) { g.DrawImage(image, new Rectangle(0, 0, newSize, newSize), new Rectangle(0, (height - width) / 2, width, width), GraphicsUnit.Pixel); } else { g.DrawImage(image, new Rectangle(0, 0, newSize, newSize), new Rectangle((width - height) / 2, 0, height, height), GraphicsUnit.Pixel); } #region 加入FTP|分布式-vebin.h:2012.12.12 SaveImage(b, newFileName, GetCodecInfo("image/" + GetFormat(fileName).ToString().ToLower()), upFileEntity); #endregion } finally { image.Dispose(); //b.Dispose(); } }
/// <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, UpFileEntity upfileEntity) { //设置 原图片 对象的 EncoderParameters 对象 EncoderParameters parameters = new EncoderParameters(1); parameters.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, ((long)100)); #region 加入FTP|分布式-vebin.h:2012.12.12 SaveThumb(image, savePath, ici, parameters, upfileEntity); #endregion //image.Save(savePath, ici, parameters); //parameters.Dispose(); }