CSharp examples for System.Drawing.Imaging:Bitmap
Letter Watermark
using System.Drawing.Drawing2D; using System.Drawing.Imaging; using System.Drawing; using System.IO;/*from w w w . jav a 2 s.com*/ using System.Collections; using System; public class Main{ public static string LetterWatermark(string path, int size, string letter, Color color, string location) { string kz_name = Path.GetExtension(path); if (kz_name == ".jpg" || kz_name == ".bmp" || kz_name == ".jpeg") { DateTime time = DateTime.Now; string filename = "" + time.Year.ToString() + time.Month.ToString() + time.Day.ToString() + time.Hour.ToString() + time.Minute.ToString() + time.Second.ToString() + time.Millisecond.ToString(); Image img = Bitmap.FromFile(path); Graphics gs = Graphics.FromImage(img); ArrayList loca = GetLocation(location, img, size, letter.Length); Font font = new Font("??", size); Brush br = new SolidBrush(color); gs.DrawString(letter, font, br, float.Parse(loca[0].ToString()), float.Parse(loca[1].ToString())); gs.Dispose(); string newpath = Path.GetDirectoryName(path) + filename + kz_name; img.Save(newpath); img.Dispose(); File.Copy(newpath, path, true); if (File.Exists(newpath)) { File.Delete(newpath); } } return path; } }