Main Site Documentation

Problem with picture_captured function?


#1

Hello, I’m developing an application that if someone digits the wrong passcode, the system takes a picture and sends it to a webserver and also saves it into the SD
The problem is that the first time the system works, the second time don’t.
Inside the picture_captured function I write the webserver code and the SD code, if I comment one of them, the other still doesn’t work, so is it a problem with the camera function? (with the webserver I’ve got a 10054 error and no photo saved, with the SD no error but still no photo saved)

Here is part of the code:

        private void camera_PictureCaptured(Camera sender, GT.Picture picture)
        {
                  SetTime();
                  POSTContent postData = POSTContent.CreateBinaryBasedContent(picture.PictureData);
        
                  HttpRequest reqData = HttpHelper.CreateHttpPostRequest("http://192.168.43.206/takeimage/webserver.php", postData, "image/bmp");
      
                  reqData.SendRequest();
            
                  SaveSD(picture);
            
                  Glide.MainWindow = wind4;
            
        }

Thank you very much


#2

Update: I solved with the SD code, it was a problem with the setTime function that I deleted.
So the problem now is only with the webserver

I tried calling back the camera.takepicture() inside the picture_captured, and it worked, so it’s like a problem that exiting picture_captured thread, the second time the webserver doesn’t work.
Is there a way to solve this?


#3

I solved the problem, I write here in order to help others.
Basically I do not send the entire picture, but piece by piece using a HttpWebRequest.
In this way (slower) I have no error

Code:

 HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create("http://192.168.43.206/takeimage/webserver2.php");
        httpWebRequest.Method = "POST";

        var pic = picture.PictureData;
        httpWebRequest.ContentLength = pic.Length;
        httpWebRequest.ContentType = "image/bmp";
        using (Stream stream = httpWebRequest.GetRequestStream())
        {
            int written = 0;
            while (written < pic.Length)
            {
                int toWrite = System.Math.Min(8192, pic.Length - written);
                stream.Write(pic, written, toWrite);
                written += toWrite;
                System.Threading.Thread.Sleep(500);
            }
        }
        var response = httpWebRequest.GetResponse() as HttpWebResponse;