Bhavesh Vankar

Bhavesh Vankar

  • 761
  • 1.1k
  • 88k

C# Crop Image Code

Sep 7 2020 4:43 AM
i have one crop button image to crop image using jquery while selecting area for the crop image area selecting but when press crop button the image is not croping and displaying in image canvas below is my code kindly please suggest me.
  1. string filename = "~/CapturedImage/"+ DateTime.Now.ToString("dd-MM-yy hh-mm") + ".jpg";  
  2. //string filename = "~/CapturedImage/V_Image.jpg";  
  3. string FilePath = Path.Combine(Server.MapPath("~/CapturedImage"));  
  4. int x = Convert.ToInt32(X.Value);  
  5. int y = Convert.ToInt32(Y.Value);  
  6. int w = Convert.ToInt32(W.Value);  
  7. int h = Convert.ToInt32(H.Value);  
  8. //Loan The Image from location  
  9. if (File.Exists(filename))  
  10. {  
  11.     System.Drawing.Image image = Bitmap.FromFile(HttpContext.Current.Request.PhysicalApplicationPath + @"\CapturedImage\" + DateTime.Now.ToString("dd-MM-yy hh-mm") + ".jpg");  
  12.     Bitmap bmpimage = new Bitmap(w, h, image.PixelFormat);  
  13.     Graphics grpx = Graphics.FromImage(bmpimage);  
  14.     grpx.DrawImage(image, new Rectangle(0, 0, w, h), new Rectangle(x, y, w, h), GraphicsUnit.Pixel);
  15.     bmpimage.Save(HttpContext.Current.Request.PhysicalApplicationPath + @"\CroppedImage\" + DateTime.Now.ToString("dd-MM-yy hh-mm") + ".jpg", image.RawFormat);  
  16.     imgCapture.Dispose();  
  17.     bmpimage = null;  
  18.     imgCapture.ImageUrl = @"\CroppedImage\" + DateTime.Now.ToString("dd-MM-yy hh-mm") + ".jpg";  
  19.     // imgCapture.ImageUrl = @"\CroppedImage\V_Image.jpg";

Answers (3)