using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;
using Telerik.Web.UI.Editor.DialogControls;
using System.Drawing;
using System.Drawing.Imaging;  

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        RadEditor1.ImageManager.ViewPaths = new string[] { "~/Images" };
        RadEditor1.ImageManager.UploadPaths = new string[] { "~/Images" };
        RadEditor1.ImageManager.ContentProviderTypeName = typeof(myprovider).AssemblyQualifiedName; 
    }

    public class myprovider : Telerik.Web.UI.Widgets.FileSystemContentProvider
    {

        public myprovider(HttpContext context, string[] searchPatterns, string[] viewPaths, string[] uploadPaths, string[] deletePaths, string selectedUrl, string selectedItemTag)
            : base(context, searchPatterns, viewPaths, uploadPaths, deletePaths, selectedUrl, selectedItemTag)
        {
        }

        public override string StoreFile(UploadedFile file, string path, string name, params string[] arguments)
        {
            System.Drawing.Image objImage = System.Drawing.Image.FromStream(file.InputStream);//From File
            int height = objImage.Height;//Actual image width
            int width = objImage.Width;//Actual image height
            System.Drawing.Bitmap bitmapimage = new System.Drawing.Bitmap(objImage, width, height);// create bitmap with same size of Actual image
            System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bitmapimage);
            //Creates a System.Drawing.Color structure from the four ARGB component
            //(alpha, red, green, and blue) values. Although this method allows a 32-bit value
            // to be passed for each component, the value of each component is limited to 8 bits.
            
            //Adding watermark text on image
            //create Brush
            //SolidBrush brush = new SolidBrush(Color.FromArgb(113, 255, 255, 255));
            //g.DrawString("WaterMark sample", new Font("Arial", 18, System.Drawing.FontStyle.Bold), brush, 0, 100);

            //Adding watermark icon on the image
            Bitmap logo = new Bitmap(this.Context.Server.MapPath("~/images/WaterMark.jpg"));
            g.DrawImage(logo, new Point(70, 70));

            string result = VirtualPathUtility.AppendTrailingSlash(path) + name;
           
            bitmapimage.Save(Context.Server.MapPath( result));
            g.Dispose();
            bitmapimage.Dispose();

            
            //string result = base.StoreFile(file, path, newFileName, arguments); 
            return result;
        }
    } 
}
 