📄 myaspnetbimage.aspx.cs
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Configuration;
namespace Example_11_9
{
/// <summary>
/// Summary description for MyAspNetWord.
/// </summary>
public class MyAspNetBImage : System.Web.UI.Page
{
private readonly string FILEPATH = ConfigurationSettings.AppSettings["FILEPATH"].ToString();
private void Page_Load(object sender, System.EventArgs e)
{
if(!Page.IsPostBack)
{
///创建水印
CreateBackImage("用ASP.NET实现简单的文字水印");
}
}
private void CreateBackImage(String str)
{
///获取图片
String filePath = Server.MapPath(FILEPATH);
System.Drawing.Image img = System.Drawing.Image.FromFile(filePath);
///创建图片
Graphics graphics = Graphics.FromImage(img);
graphics.DrawImage(img,0,0,img.Width,img.Height);
///定义字段和画笔
Font font = new Font("方正大标宋简体",16);
Brush brush = new SolidBrush(Color.Green);
///打印水印
graphics.DrawString(str,font,brush,30,100);
///保存并输出图片
img.Save(Response.OutputStream,System.Drawing.Imaging.ImageFormat.Jpeg);
///是否绘画资源
graphics.Dispose();
img.Dispose();
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -