In my project i want to capture image all done but now its generating error and image not capturing below is my code kindly help me to solve the error.
image not getting in folder using below code. kindly please solve and suggest me good code.
on my captureimage.aspx
jquery code for capture image
- protected void Page_Load(object sender, EventArgs e)
- {
- if (!this.IsPostBack)
- {
- if (Request.InputStream.Length > 0)
- {
- using (StreamReader myreader = new StreamReader(Request.InputStream))
- {
- string myhexString = Server.UrlEncode(myreader.ReadToEnd());
- string myimageName = DateTime.Now.ToString("Image.jpg");
- string myimagePath = string.Format ("~/CapturedImage/Image.jpg", myimageName);
- File.WriteAllBytes(Server.MapPath(myimagePath), ConvertHexToBytes(myhexString));
- Session["visitorimage"] = ResolveUrl(myimagePath);
- }
- }
- }
- }
- private static byte[] ConvertHexToBytes(string hex)
- {
- byte[] bytes = new byte[hex.Length / 2];
- for (int i = 0; i < hex.Length; i += 2)
- {
- bytes[i / 2] = Convert.ToByte(hex.Substring(i, 2), 16);
- }
- return bytes;
- }
- [WebMethod(EnableSession = true)]
- public static string GetCapturedImage()
- {
- string Imageurl = HttpContext.Current.Session ["visitorimage"].ToString();
- HttpContext.Current.Session["visitorimage"] = null;
- return Imageurl;
- }
"An exception of type 'System.IO.FileNotFoundException' occurred in System.Drawing.dll but was not handled in user code "
Crop code is..
- protected void btnCrop_Click(object sender, EventArgs e)
- {
- string FilePath = Path.Combine("~/CapturedImage/Image.jpg");
- int x = Convert.ToInt32(X.Value);
- int y = Convert.ToInt32(Y.Value);
- int w = Convert.ToInt32(W.Value);
- int h = Convert.ToInt32(H.Value);
- //System.Drawing.Image image = Bitmap.FromFile(HttpContext.Current.Request.PhysicalApplicationPath + @"\CapturedImage\" + DateTime.Now.ToString("dd-MM-yy hh-mm") + ".jpg");
- System.Drawing.Image image = Bitmap.FromFile(HttpContext.Current.Request.PhysicalApplicationPath + @"\CapturedImage\Image.jpg");
- Bitmap bmp = new Bitmap(w, h, image.PixelFormat);
- Graphics g = Graphics.FromImage(bmp);
- g.DrawImage(image, new Rectangle(0, 0, w, h), new Rectangle(x, y, w, h), GraphicsUnit.Pixel);
- //bmp.Save(HttpContext.Current.Request.PhysicalApplicationPath + @"\CroppedImage\" + DateTime.Now.ToString("dd-MM-yy hh-mm") + ".jpg", image.RawFormat);
- bmp.Save(HttpContext.Current.Request.PhysicalApplicationPath + @"\CroppedImage\Image.jpg", image.RawFormat);
- //imgCapture.ImageUrl = @"\CroppedImage\" + DateTime.Now.ToString("dd-MM-yy hh-mm") + ".jpg";
- imgCapture.ImageUrl = "~/CroppedImage/Image.jpg";
- }


Gaggan Malik4 reputationPosted Sep 10, 2020, 5:18 AM EDT
Darshan ShahRank #1,135 · 1.6K reputationPosted Sep 11, 2020, 12:00 AM EDT
Bhavesh VankarRank #1,147 · 1.6K reputationPosted Sep 11, 2020, 12:12 AM EDT