zoukankan      html  css  js  c++  java
  • 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;

                }

            }

        }

    }

  • 相关阅读:
    JS/JQuery获取当前元素的上一个/下一个兄弟级元素等元素的方法
    目前流行前端几大UI框架
    C#客户端嵌入Chrome浏览器的实现
    ARM编译中的RO、RW和ZI DATA区段
    如何成为优秀的技术Leader?做到这三点就够了
    VMware虚拟机中的CentOS安装Nginx后本机无法访问的解决办法
    Centos下安装nginx步骤解析
    centos修改、保存文件的详细步骤
    configure: error: C preprocessor "arm-linux-gnueabihf-g++" fails sanity check
    有关fgetc配合feof逐行读取文件最后一行读取两遍的错觉?
  • 原文地址:https://www.cnblogs.com/hpp3501/p/2721567.html
Copyright © 2011-2022 走看看