asp.net 图片加水印效果

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="ShuiYin._Default" %>
    <%@ Import Namespace="System.IO" %>
        <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ">
        <html xmlns="">          
            <head id="Head1" runat="server">
                <title>
                    无标题页
                </title>
            </head>
            <body>
                <form id="form1" runat="server">
                    <div>
                        <% string[] files=D irectory.GetFiles(Request.MapPath("Images/BookCovers/")); %>
                            <table border="1" bgcolor="#e6fbff">
                                <%

              foreach (string file in files) { string filename=f ile.Substring(file.LastIndexOf(@"\") + 1);

           %>
                                    <tr>
                                        <td>
                                            <a href="ImgHandler.ashx?ISBN=<%=filename.Substring(0, filename.LastIndexOf(". "))%>">
                                                <%=filename %>
                                            </a>
                                        </td>
                                    </tr>
                                    <%} %>
                            </table>
                    </div>
                </form>
            </body>
        </html>

 

//实现水印的

Handler using System;

using System.Collections;

using System.Data;

using System.Linq;

using System.Web;

using System.Web.Services;

using System.Web.Services.Protocols;

using System.Xml.Linq;

using System.Drawing;

namespace ShuiYin

{    

/// <summary>    

/// $codebehindclassname$ 的摘要说明    

/// </summary>    

[WebService(Namespace = ")]    

[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]    

public class Handler1 : IHttpHandler     {

        public void ProcessRequest(HttpContext context)

        {

            string filename = context.Request.QueryString["ISBN "] + ".jpg ";

            string filePath = context.Request.MapPath("Images / BookCovers / ") + filename;

            string LogoPath = context.Request.MapPath("Images / hpp1.jpg ");

            Image fileImage = Image.FromFile(filePath);

            Image LogoImage = Image.FromFile(LogoPath);

            Graphics g = Graphics.FromImage(fileImage);

            g.DrawImage(LogoImage, new Rectangle(fileImage.Width - LogoImage.Width, fileImage.Height - LogoImage.Height, LogoImage.Width, LogoImage.Height), 0, 0, LogoImage.Width, LogoImage.Height, GraphicsUnit.Pixel);

            LogoImage.Dispose();

            g.Save();

            fileImage.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);

            g.Dispose();

            fileImage.Dispose();

        }

        public bool IsReusable

        {

            get

            {

                return false;

            }

        }

    }

}

转载于:https://www.cnblogs.com/hpp3501/archive/2012/10/12/2721567.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值