I have a monitoring system, and I want to save a snapshot from the camera when an alarm is triggered. I tried many methods to do this ... and it all works great, stream a snapshot from the camera, and then save it as a jpg in PC. picture (jpg format, 1280 * 1024,140KB) .. Thats fine But my problem is application performance ... The application will need about 20-30 seconds to read a couple, this is not acceptable because this method will be called every two seconds. I need to know what is wrong with this code, and how can I get it much faster than this.? Thanks in advance Code:
string sourceURL = "http://192.168.0.211/cgi-bin/cmd/encoder?SNAPSHOT";
byte[] buffer = new byte[200000];
int read, total = 0;
WebRequest req = (WebRequest)WebRequest.Create(sourceURL);
req.Credentials = new NetworkCredential("admin", "123456");
WebResponse resp = req.GetResponse();
Stream stream = resp.GetResponseStream();
while ((read = stream.Read(buffer, total, 1000)) != 0)
{
total += read;
}
Bitmap bmp = (Bitmap)Bitmap.FromStream(new MemoryStream(buffer, 0,total));
string path = JPGName.Text+".jpg";
bmp.Save(path);
Ramah source
share