web.config 代码
<add verb="*" path="imageSY/*.jpg" type="shuiyin"/>
shuiyin.cs代码
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Drawing;
using System.IO;
using System.Drawing.Imaging;
/// <summary>
/// shuiyin 的摘要说明
/// </summary>
public class shuiyin:IHttpHandler
{
private const string COVERSADDR = "~/imageSY/";//存放原始图片的文件夹
private const string WATERMARK_URL = "~/imageSY/logo-3.png";//水印图片的路径
private const string DEFAULTIMAGE_URL = "~/imageSY/pro_img.jpg";//默认图片路径
public shuiyin()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
#region IHttpHandler 成员
public bool IsReusable
{
get { return false; }
}
public void ProcessRequest(HttpContext context)
{
ImageAttributes imageAttributes = new ImageAttributes();
ColorMap colorMap = new ColorMap();
//My watermark was defined with a background of 100% Green this will
//be the color we search for and replace with transparency
colorMap.OldColor = Color.FromArgb(255, 0, 255, 0);
colorMap.NewColor = Color.FromArgb(255, 255, 255, 255);
ColorMap[] remapTable = { colorMap };
imageAttributes.SetRemapTable(remapTable, ColorAdjustType.Bitmap);
float[][] colorMatrixElements = {
new float[] {1.0f, 0.0f, 0.0f, 0.0f, 0.0f},
new float[] {0.0f, 1.0f, 0.0f, 0.0f, 0.0f},
new float[] {0.0f, 0.0f, 1.0f, 0.0f, 0.0f},
new float[] {0.0f, 0.0f, 0.0f, 0.3f, 0.0f},
new float[] {0.0f, 0.0f, 0.0f, 0.0f, 1.0f}};
ColorMatrix wmColorMatrix = new ColorMatrix(colorMatrixElements);
imageAttributes.SetColorMatrix(wmColorMatrix, ColorMatrixFlag.Default,
ColorAdjustType.Bitmap);
System.Drawing.Image Covers = null;
if (File.Exists(context.Request.PhysicalPath))
{
Covers = System.Drawing.Image.FromFile(context.Request.PhysicalPath);
System.Drawing.Image watermark = System.Drawing.Image.FromFile(context.Request.MapPath(WATERMARK_URL));
Graphics p = Graphics.FromImage(Covers);
if (Covers.Width < 550)
{
p.DrawImage(watermark, new Rectangle(Covers.Width - watermark.Width+20, Covers.Height - watermark.Height - 50, watermark.Width, watermark.Height), 0, 0, watermark.Width, watermark.Height, GraphicsUnit.Pixel);
}
else
{
p.DrawImage(watermark, new Rectangle(Covers.Width - watermark.Width, Covers.Height - watermark.Height - 50, watermark.Width, watermark.Height), 0, 0, watermark.Width, watermark.Height, GraphicsUnit.Pixel);
} p.Dispose();
watermark.Dispose();
}
else
{
Covers = System.Drawing.Image.FromFile(context.Request.MapPath(DEFAULTIMAGE_URL));
}
context.Response.ContentType = "image/Png";
Covers.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
Covers.Dispose();
context.Response.End();
}
#endregion
}
asp.net上传到FTP后 水印图片显示不了了 是什么原因??
答案:1 悬赏:40 手机版
解决时间 2021-07-28 21:57
- 提问者网友:一抹荒凉废墟
- 2021-07-28 10:23
最佳答案
- 五星知识达人网友:你可爱的野爹
- 2021-07-28 10:40
路径对吗?
要是空间支持。net多数原因就是路径 问题
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯