Beispiel #1
0
        public static FileModel Upload(HttpPostedFileBase postedFile)
        {
            //上传和返回(保存到数据库中)的路径
            string      uppath   = string.Empty;
            string      savepath = string.Empty;
            HttpContext context  = HttpContext.Current;
            //创建图片新的名称
            string nameImg = DateTime.Now.ToString("yyyyMMddHHmmssfff");
            string strPath = postedFile.FileName;
            string type    = strPath.Substring(strPath.LastIndexOf(".") + 1).ToLower();

            if (ValidateImg(postedFile))
            {
                //拼写上传图片的路径
                savepath  = context.Server.MapPath(Configs.GetValue("FileSrc") + type + "/");
                savepath += nameImg + "." + type;
                uppath    = context.Server.MapPath(Configs.GetValue("FileSrc")) + type;
                FileHelper.CreateDirectory(uppath);
                FileHelper.CreateDirectory(uppath + "/水印"); //水印图片地址
                FileHelper.CreateDirectory(uppath + "/文字"); //文字图片地址
                //uppath += nameImg + "." + type;
                //上传图片
                postedFile.SaveAs(savepath);
                ImageManager writer = new ImageManager();

                //调用很简单 im.SaveWatermark(原图地址, 水印地址, 透明度, 水印位置, 边距,保存到的位置);
                writer.SaveWatermark(savepath, context.Server.MapPath(Configs.GetValue("FileSrc")) + "Logo.png", 0.9f, ImageManager.WatermarkPosition.RigthBottom, 10, uppath + "/水印/" + nameImg + "." + type);
                writer.AddTextToImg(savepath, "蓝色星球", uppath + "/文字/" + nameImg + "." + type);
            }
            return(new FileModel()
            {
                RealName = nameImg + "." + type,
                FileName = strPath,
                FileMax = postedFile.ContentLength.ToString()
            });
        }