C#給圖片加水印的簡略完成辦法。本站提示廣大學習愛好者:(C#給圖片加水印的簡略完成辦法)文章只能為提供參考,不一定能成為您想要的結果。以下是C#給圖片加水印的簡略完成辦法正文
本文實例講述了C#給圖片加水印的簡略完成辦法。分享給年夜家供年夜家參考。詳細剖析以下:
這裡完成本網站圖片掩護功效類:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Drawing;//image的定名空間
namespace 完成本網站圖片掩護功效
{
public class yanzhengma:IHttpHandler
{
public bool IsReusable
{
get { throw new NotImplementedException(); }
}
public void ProcessRequest(HttpContext context)
//要求的辦法
{
Image img = Image.FromFile(context.Request.PhysicalPath);
//1:從文件中獲得圖片;獲得要求的文件的物理途徑
Graphics g = Graphics.FromImage(img);
//2:聲明graphicse把img做為填充他的參數
g.DrawString("net",new Font("宋體",20,FontStyle.Italic),Brushes.Blue,10,10);
//3:在graphicse上寫圖片
img.Save(context.Response.OutputStream,System.Drawing.Imaging.ImageFormat.Jpeg);
//4:保留(保留到甚麼甚麼流裡,甚麼格局保留)
context.Response.Flush();
//5:從緩存區中輸入
context.Response.End();
//6:停止
//7:設置裝備擺設
}
}
}
webform1.aspx:
<div> <%-- <asp:GridView ID="GridView1" runat="server"> </asp:GridView> <asp:SqlDataSource ID="SqlDataSource1" runat="server"> </asp:SqlDataSource>--%> <asp:Image ID="Image1" runat="server" imageurl="imgs/1.jpg"/> <%--<image src="http://localhost:2309/WebForm1.aspx"> </image>--%> </div>
設置裝備擺設:
<httpHandlers> <add verb="*" path="imgs/*.jpg" type="完成本網站圖片掩護功效.yanzhengma"/> <!--第一個屬性verb是處置甚麼樣的文件,path是處置誰人文件夾下的圖片, type是要設置裝備擺設的文件類--> </httpHandlers>
願望本文所述對年夜家的C#法式設計有所贊助。