using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Drawing; using System.Drawing.Imaging; /// /// Summary description for ImageWatermarkHandler /// namespace Tehased { public class ImageFactory : IHttpHandlerFactory { #region IHttpHandlerFactory Members public IHttpHandler GetHandler(HttpContext context, string requestType, string url, string pathTranslated) { if (context.User.Identity.IsAuthenticated) return new Ohjurid.ImageHandler(); else return new Ohjurid.ImageWatermarkHandler(); } public void ReleaseHandler(IHttpHandler handler) { } #endregion } } namespace Ohjurid { public class ImageWatermarkHandler : IHttpHandler { #region IHttpHandler Members public bool IsReusable { get { return false; } } public void ProcessRequest(HttpContext context) { Bitmap bmp = new Bitmap(context.Request.PhysicalPath); Graphics pilt = Graphics.FromImage(bmp); //pilt.DrawString("Näidis!", // new Font("Verdana", 14, FontStyle.Bold), // new SolidBrush(Color.Beige), 0, bmp.Height - 22); pilt.RotateTransform(45); pilt.DrawString("NÄIDIS", new Font("Verdana", 100, FontStyle.Bold), new SolidBrush(Color.FromArgb(113, 255, 0, 0)) //new SolidBrush(Color.Red) , 100, -100); bmp.Save(context.Response.OutputStream, ImageFormat.Jpeg); } #endregion } public class ImageHandler : IHttpHandler { #region IHttpHandler Members public bool IsReusable { get { return false; } } public void ProcessRequest(HttpContext context) { Bitmap bmp = new Bitmap(context.Request.PhysicalPath); bmp.Save(context.Response.OutputStream, ImageFormat.Jpeg); } #endregion } }