<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> <title>無標題頁</title></head><body> <form id="form1" runat="server"> <div> <table> <tr> <td style="width: 100px"> 上傳圖片:</td> <td style="width: 100px"> <asp:FileUpload ID="FileUpload1" runat="server" /></td> <td style="width: 100px"> <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="上傳" /></td> </tr> <tr> <td style="width: 100px" valign="top"> 原圖:</td> <td style="width: 100px"> <asp:Image ID="Image1" runat="server" /></td> <td style="width: 100px"> </td> </tr> <tr> <td style="width: 100px" valign="top"> 縮圖:</td> <td style="width: 100px"> <asp:Image ID="Image2" runat="server" /></td> <td style="width: 100px"> </td> </tr> <tr> <td style="width: 100px" valign="top"> 加浮水印:</td> <td style="width: 100px"> <asp:Image ID="Image3" runat="server" /></td> <td style="width: 100px"> </td> </tr> </table> </div> </form></body></html>
view plain
copy to clipboard
print
?
- using System;
- using System.Data;
- using System.Configuration;
- using System.Web;
- using System.Web.Security;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Web.UI.WebControls.WebParts;
- using System.Web.UI.HtmlControls;
- using System.Drawing;
-
- public partial class _Default : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
-
- }
- protected void Button1_Click(object sender, EventArgs e)
- {
- string filename = FileUpload1.FileName;
- string nowpath = Server.MapPath(".") + "\\";
- filename = nowpath + filename;
-
- //儲存原圖
- FileUpload1.SaveAs(filename);
-
- System.Drawing.Image image, newimage, syimage;
- System.Drawing.Image.GetThumbnailImageAbort callb = null;
- image = System.Drawing.Image.FromFile(filename);
- syimage = System.Drawing.Image.FromFile(Server.MapPath(".") + "\\" + "縮圖.gif");//要目錄下放一個"縮圖.gif"檔案,可以從網上下載:http://www.baidu.com/img/baidu.gif
-
- //儲存縮圖
- newimage = image.GetThumbnailImage(100, 100, callb, new IntPtr());
- newimage.Save(filename + ".縮圖.png");
- newimage.Dispose();
-
- //處理原圖片
- Graphics g = Graphics.FromImage(image);
- Font f = new Font("隸書", 16);
- Brush b = new SolidBrush(ColorTranslator.FromHtml("#FF0000"));
- string addText = "文字浮水印內容";
- g.DrawString(addText, f, b, 10, 10);
- g.DrawImageUnscaled(syimage, 50, 50);
- //g.DrawImage(newimage,50,50,100,100);
- g.Dispose();
-
- //產生浮水印圖
- image.Save(filename + ".浮水印.png");
-
- image.Dispose();
- syimage.Dispose();
-
- Image1.ImageUrl = FileUpload1.FileName;
- Image2.ImageUrl = FileUpload1.FileName + ".縮圖.png";
- Image3.ImageUrl = FileUpload1.FileName + ".浮水印.png";
-
- }
- }