/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public virtual void OnCropping(Object sender, CropImageEventArgs e) { if (Cropping != null) { Cropping(this, e); } }
/// <summary> /// /// </summary> /// <param name="path"></param> public void Crop(string path) { CropImageEventArgs args = new CropImageEventArgs(); args.x = Convert.ToInt32(Page.Request["_x_" + this.ClientID]); args.y = Convert.ToInt32(Page.Request["_y_" + this.ClientID]); args.width = Convert.ToInt32(Page.Request["_w_" + this.ClientID]); args.height = Convert.ToInt32(Page.Request["_h_" + this.ClientID]); OnCropping(this, args); // create property called saveas and save this file to there. System.Drawing.Graphics g = null; System.Drawing.Bitmap cropedImage = null; drawing.Image image = drawing.Image.FromFile(HttpContext.Current.Server.MapPath(this.ImagePath)); cropedImage = new System.Drawing.Bitmap(args.width, args.height, image.PixelFormat); g = System.Drawing.Graphics.FromImage(cropedImage); drawing.Rectangle _rec = new drawing.Rectangle(0, 0, args.width, args.height); drawing.Rectangle _rec2 = new drawing.Rectangle( args.x, args.y, args.width, args.height); g.DrawImage(image, _rec, _rec2.X, _rec2.Y, _rec2.Width, _rec2.Height, drawing.GraphicsUnit.Pixel); image.Dispose(); cropedImage.Save(HttpContext.Current.Server.MapPath(path)); g.Dispose(); cropedImage.Dispose(); OnCropped(this, args); }