?? 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 + -