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; } } }}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。