public void ProcessRequest(HttpContext context) { string picpath = context.Request["picpath"]; string warning = ""; string waterpic = ImageDealLib.makewatermark( picpath, "/UploadImages/dolphin48.png", ImageDealLib.WaterType.RightDown, "/UploadImages/", ImageDealLib.ImageType.JPEG, ImageDealLib.FileCache.Save, out warning); context.Response.Write(waterpic); }
protected void Page_Load(object sender, EventArgs e) { buser.CheckIsLogin(); if (function.isAjax()) { string action = Request.Form["action"], vpath = Request.Form["vpath"], result = "", warning = "";//动作,需要加水印的图片路径 if (vpath.Contains("?")) { vpath = vpath.Substring(0, vpath.IndexOf("?")); } switch (action) { case "crop": //根据提交的图片路径与宽度等参数,完成剪切 { int x1 = int.Parse(Request.Form["x1"]); int y1 = int.Parse(Request.Form["y1"]); int width = int.Parse(Request.Form["width"]); int height = int.Parse(Request.Form["height"]); savePath += (function.GetRandomString(4) + Path.GetFileName(vpath)); result = ImageDealLib.imgcrop(vpath, savePath, x1, y1, width, height, ImageDealLib.FileCache.Save, out warning); } break; case "rotate": { int angle = DataConverter.CLng(Request.Form["angle"]); Bitmap bmp = imgHelper.Rotate(vpath, angle); savePath += function.GetRandomString(6) + Path.GetExtension(vpath); result = imgHelper.SaveImg(savePath, bmp); bmp.Dispose(); } break; case "zoom": //缩放 { int width = int.Parse(Request.Form["width"]); int height = int.Parse(Request.Form["height"]); savePath += (function.GetRandomString(4) + Path.GetFileName(vpath)); Bitmap bmp = imgHelper.ZoomImg(vpath, height, width); result = imgHelper.SaveImg(savePath, bmp); } break; case "fontwater": //文字水印 { System.Drawing.Image fontimg = AddFontWater(savePath + function.GetRandomString(6) + ".jpg"); savePath += "fontw_" + Path.GetFileName(vpath); result = ImageDealLib.makewatermark(vpath, fontimg, GetWaterType(Request.Form["pos"]), savePath, ImageDealLib.ImageType.JPEG, ImageDealLib.FileCache.Save, out warning); result += "?" + function.GetRandomString(6); } break; case "imgwater": //水印图片路径 { string watervpath = Request.Form["watervpath"]; int trans = DataConverter.CLng(Request.Form["trans"]); savePath += "imgw_" + Path.GetFileName(vpath); result = ImageDealLib.makewatermark(vpath, watervpath, GetWaterType(Request.Form["pos"]), savePath, ImageDealLib.ImageType.JPEG, ImageDealLib.FileCache.Save, out warning, trans); result += "?" + function.GetRandomString(6); } break; } Response.Write(result); Response.Flush(); Response.End(); } if (!IsPostBack) { M_UserInfo mu = buser.GetLogin(); string ipath = Request.QueryString["ipath"].ToLower().Replace("/uploadfiles/user/", ""); string UserPath = "/UploadFiles/User/" + mu.UserName + mu.UserID + "/" + ipath.TrimStart('/');//不做过多的限制,如需要文件安全,则使用单独的文件服务器 if (string.IsNullOrEmpty(UserPath) || !SafeC.IsImage(UserPath)) { function.WriteErrMsg("只允许编辑图片文件!"); } if (!Directory.Exists(savePath)) { Directory.CreateDirectory(Server.MapPath(savePath)); } if (!File.Exists(Server.MapPath(UserPath))) { function.WriteErrMsg("需要修改的图片" + UserPath + "不存在"); } NowImg_Hid.Value = SourceImg_Hid.Value = UserPath; System.Drawing.Image img = System.Drawing.Image.FromFile(Server.MapPath(UserPath)); ImgWidth_Hid.Value = img.Width.ToString(); ImgHeight_Hid.Value = img.Height.ToString(); RPT.DataSource = GetWaterImgDT(); RPT.DataBind(); img.Dispose(); //string warning; //----剪切图 //vpath = ImageDealLib.imgcrop("/test/222.jpg", "/test/", 200, 200, 200, 200, ImageDealLib.FileCache.Save, out warning); //function.WriteErrMsg(vpath); //----生成水印 //string watervpath = AddFontWater(); //ImageDealLib.makewatermark("/test/222.jpg", "/test/usbqyr.jpg", ImageDealLib.WaterType.RightDown, "/test/", ImageDealLib.ImageType.JPEG, ImageDealLib.FileCache.Save, out warning); //----我们的水印 //WaterImages water = new WaterImages(); //string localPath = Server.MapPath("/test/222.jpg"); //string tempurl = Server.MapPath("/test/watered12.jpg"); //water.DrawImage(localPath, function.VToP("/Images/admin_logo.jpg"), tempurl); } }
protected void Page_Load(object sender, EventArgs e) { if (B_Admin.GetLogin() == null) { B_User.CheckIsLogged(); } else { B_Admin.CheckIsLogged(); } if (function.isAjax()) { string action = Request.Form["action"], vpath = Request.Form["vpath"], result = "", warning = "";//动作,需要加水印的图片路径 if (vpath.Contains("?")) { vpath = vpath.Substring(0, vpath.IndexOf("?")); } switch (action) { case "crop": //根据提交的图片路径与宽度等参数,完成剪切 { int x1 = int.Parse(Request.Form["x1"]); int y1 = int.Parse(Request.Form["y1"]); int width = int.Parse(Request.Form["width"]); int height = int.Parse(Request.Form["height"]); savePath += (function.GetRandomString(4) + Path.GetFileName(vpath)); result = ImageDealLib.imgcrop(vpath, savePath, x1, y1, width, height, ImageDealLib.FileCache.Save, out warning); } break; case "rotate": { int angle = DataConverter.CLng(Request.Form["angle"]); Bitmap bmp = imgHelper.Rotate(vpath, angle); savePath += function.GetRandomString(6) + Path.GetExtension(vpath); result = imgHelper.SaveImg(savePath, bmp); bmp.Dispose(); } break; case "zoom": //缩放 { int width = int.Parse(Request.Form["width"]); int height = int.Parse(Request.Form["height"]); savePath += (function.GetRandomString(4) + Path.GetFileName(vpath)); Bitmap bmp = imgHelper.ZoomImg(vpath, height, width); result = imgHelper.SaveImg(savePath, bmp); } break; case "fontwater": //文字水印 { System.Drawing.Image fontimg = AddFontWater(savePath + function.GetRandomString(6) + ".jpg"); savePath += "fontw_" + Path.GetFileName(vpath); result = ImageDealLib.makewatermark(vpath, fontimg, GetWaterType(Request.Form["pos"]), savePath, ImageDealLib.ImageType.JPEG, ImageDealLib.FileCache.Save, out warning); result += "?" + function.GetRandomString(6); } break; case "imgwater": //水印图片路径 { string watervpath = Request.Form["watervpath"]; int trans = DataConverter.CLng(Request.Form["trans"]); savePath += "imgw_" + Path.GetFileName(vpath); result = ImageDealLib.makewatermark(vpath, watervpath, GetWaterType(Request.Form["pos"]), savePath, ImageDealLib.ImageType.JPEG, ImageDealLib.FileCache.Save, out warning, trans); result += "?" + function.GetRandomString(6); } break; } Response.Write(result); Response.Flush(); Response.End(); } if (!IsPostBack) { if (string.IsNullOrEmpty(IPath) || !SafeC.IsImage(IPath)) { function.WriteErrMsg("只允许编辑图片文件!"); } if (!Directory.Exists(Server.MapPath(savePath))) { Directory.CreateDirectory(Server.MapPath(savePath)); } if (!File.Exists(Server.MapPath(IPath))) { function.WriteErrMsg("需要修改的图片" + IPath + "不存在"); } NowImg_Hid.Value = SourceImg_Hid.Value = IPath; System.Drawing.Image img = System.Drawing.Image.FromFile(Server.MapPath(IPath)); ImgWidth_Hid.Value = img.Width.ToString(); ImgHeight_Hid.Value = img.Height.ToString(); RPT.DataSource = GetWaterImgDT(); RPT.DataBind(); img.Dispose(); } }
protected void Page_Load(object sender, EventArgs e) { B_Admin.CheckIsLogged(); if (function.isAjax()) { string action = Request.Form["action"], vpath = Request.Form["vpath"], result = "", warning = "";//动作,需要加水印的图片路径 if (vpath.Contains("?")) { vpath = vpath.Substring(0, vpath.IndexOf("?")); } switch (action) { case "crop": //根据提交的图片路径与宽度等参数,完成剪切 int x1 = int.Parse(Request.Form["x1"]); int y1 = int.Parse(Request.Form["y1"]); int width = int.Parse(Request.Form["width"]); int height = int.Parse(Request.Form["height"]); savePath += (function.GetRandomString(4) + Path.GetFileName(vpath)); result = ImageDealLib.imgcrop(vpath, savePath, x1, y1, width, height, ImageDealLib.FileCache.Save, out warning); break; case "fontwater": //文字水印 { System.Drawing.Image fontimg = AddFontWater(savePath + function.GetRandomString(6) + ".jpg"); savePath += "fontw_" + Path.GetFileName(vpath); result = ImageDealLib.makewatermark(vpath, fontimg, GetWaterType(Request.Form["pos"]), savePath, ImageDealLib.ImageType.JPEG, ImageDealLib.FileCache.Save, out warning); result += "?" + function.GetRandomString(6); } break; case "imgwater": //水印图片路径 { string watervpath = Request.Form["watervpath"]; int trans = DataConverter.CLng(Request.Form["trans"]); savePath += "imgw_" + Path.GetFileName(vpath); result = ImageDealLib.makewatermark(vpath, watervpath, GetWaterType(Request.Form["pos"]), savePath, ImageDealLib.ImageType.JPEG, ImageDealLib.FileCache.Save, out warning, trans); result += "?" + function.GetRandomString(6); } break; } Response.Write(result); Response.Flush(); Response.End(); } if (!IsPostBack) { if (string.IsNullOrEmpty(IPath) || !SafeC.IsImage(IPath)) { function.WriteErrMsg("只允许编辑图片文件!"); } if (!Directory.Exists(savePath)) { Directory.CreateDirectory(Server.MapPath(savePath)); } if (!File.Exists(Server.MapPath(IPath))) { function.WriteErrMsg("需要修改的图片" + IPath + "不存在"); } NowImg_Hid.Value = SourceImg_Hid.Value = IPath; RPT.DataSource = GetWaterImgDT(); RPT.DataBind(); //string warning; //----剪切图 //vpath = ImageDealLib.imgcrop("/test/222.jpg", "/test/", 200, 200, 200, 200, ImageDealLib.FileCache.Save, out warning); //function.WriteErrMsg(vpath); //----生成水印 //string watervpath = AddFontWater(); //ImageDealLib.makewatermark("/test/222.jpg", "/test/usbqyr.jpg", ImageDealLib.WaterType.RightDown, "/test/", ImageDealLib.ImageType.JPEG, ImageDealLib.FileCache.Save, out warning); //----我们的水印 //WaterImages water = new WaterImages(); //string localPath = Server.MapPath("/test/222.jpg"); //string tempurl = Server.MapPath("/test/watered12.jpg"); //water.DrawImage(localPath, function.VToP("/Images/admin_logo.jpg"), tempurl); } }