Asp.net(C#)給圖片加上浮水印效果的類
來源:互聯網
上載者:User
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Drawing;
namespace QianBianWanHua_Lib
... {
/**//// <summary>
/// 功能說明:給圖片加浮水印,分為文字和圖片兩種
/// 程式員:段小勇
/// 日期:2007-11-12
/// </summary>
public class PicContron
...{
public PicContron()
...{
}
/**//// <summary>
/// 給圖片加上文字浮水印,位置在圖片的右下角
/// </summary>
/// <param name="PicPath">圖片路徑</param>
/// <param name="Text">在圖片上的文字</param>
public static void AddTextToPic(string PicPath,string Text)
...{
System.Drawing.Image image = System.Drawing.Image.FromFile(PicPath);
Graphics g = Graphics.FromImage(image);
int _intX = 0;
int _intY = image.Height;
try
...{
_intX = image.Width - 180;
}
catch
...{
_intX = 0;
}
try
...{
_intY = image.Height - 60;
}
catch
...{
_intY = 0;
}
g.DrawImage(image, 0, 0, image.Width, image.Height);
Font f = new Font("Verdana", 20);
Brush b = new SolidBrush(Color.Red);
g.DrawString(Text, f, b, _intX, _intY);
g.Dispose();
image.Save(PicPath+"t");
image.Dispose();
if (File.Exists(PicPath))
...{
File.Delete(PicPath);
}
if (File.Exists(PicPath+"t"))
...{
File.Move(PicPath + "t", PicPath);
}
&nb