加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

图片水印

发布时间:2020-12-17 02:08:52 所属栏目:安全 来源:网络整理
导读:using System; using System.Data; using System.Web; using System.Collections; using System.Web.Services; using System.Web.Services.Protocols; using System.IO; using System.Drawing; using System.Text; namespace xhyBookShop { ??? /// summary

using System;
using System.Data;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.IO;
using System.Drawing;
using System.Text;

namespace xhyBookShop
{
??? /// <summary>
??? /// $codebehindclassname$ 的摘要说明
??? /// </summary>
??? [WebService(Namespace = "http://tempuri.org/")]
??? [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
??? public class ImgHandler : IHttpHandler
??? {

??????? public void ProcessRequest(HttpContext context)
??????? {
??????????? //context.Response.ContentType = "text/plain";
??????????? //context.Response.Write("Hello World");
??????????? string path = context.Server.MapPath("~/BookPic/");
??????????? string fileSrc = path + context.Request["src"];
??????????? string defSrc = path + "default.jpg";
??????????? string waterSrc = path + "sign.jpg";

??????????? Image pic = null;
??????????? //创建站点图片
??????????? context.Response.ContentType = "image/jpg";
??????????? Image waterPic = Image.FromFile(waterSrc);
??????????? //创建水印绘图对象
??????????? Graphics wg = Graphics.FromImage(waterPic);
??????????? //绘制
??????????? wg.DrawString(
??????????????? "title",
??????????????? new Font("粗体",15,FontStyle.Bold),
??????????????? Brushes.Black,
??????????????? new Point(20,12));
??????????? wg.Dispose();
??????????? if (File.Exists(fileSrc))
??????????? {
??????????????? //设置输出类型
??????????????? context.Response.ContentType = "image/jpg";
??????????????? //创建图片
??????????????? pic = Image.FromFile(fileSrc);
??????????????? //绘制
??????????????? Graphics g = Graphics.FromImage(pic);
??????????????? g.DrawImage(waterPic,0);
??????????????? g.Dispose();
??????????? }
??????????? else
??????????? {
??????????????? //设置输出类型
??????????????? context.Response.ContentType = "image/jpg";
??????????????? //创建图片
??????????????? pic = Image.FromFile(defSrc);
??????????????? //创建绘图对象
??????????????? Graphics g = Graphics.FromImage(pic);
??????????????? //绘制
??????????????? g.DrawImage(waterPic,0);
??????????????? //g.DrawString(
??????????????? //??? "title",
??????????????? //??? new Font("粗体",
??????????????? //??? Brushes.Black,
??????????????? //??? new Point(0,0));
??????????????? g.DrawString(
??????????????????? "暂无图片",
??????????????????? new Font("粗体",30,
??????????????????? Brushes.Gray,
??????????????????? new Point(0,60));
??????????? }
??????????? context.Response.ContentType = "image/jpeg";
??????????? pic.Save(context.Response.OutputStream,System.Drawing.Imaging.ImageFormat.Jpeg);
??????????? pic.Dispose();

??????? }

??????? public bool IsReusable??????? {??????????? get??????????? {??????????????? return false;??????????? }??????? }??? }}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读