|
|
Hello everyone!
I have a EasyN ip Camera and I want to take the picture as .Jpg. The url that displays the image in my browser is http://192.168.1.xxx:xx/videostream.cgi.
After many hours searching in the internet I found this interest tutorial Camera Vision - video surveillance on C#,
but because I do not know much about Visual Studio did not help me very much.
Specifically, I have created a Visual C # Console Application but when I try to debugging shows some errors like: "The type or name 'HttpWebRequest' could not be found (are you missing a using directive or an assembly reference?)".
What am I doing wrong and the program not works?
Initially, What I want is the picture is automatically saved in my hard disk as .Jpg format. How can this happen?
Here is my code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication4
{
class Program
{
static void Main(string[] args)
{
string sourceURL = "http://192.168.1.xxx:xx/videostream.cgi";
byte[] buffer = new byte[100000];
int read, total = 0;
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(sourceURL);
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));
}
}
}
It would be valuable any of yours help!
Thank you!
|
|
|
|
|
Your first problem is that you have posted this in the C++ forum rather than the C#[^] one. However the error message means that a reference is missing from your project.
[edit]Right click with your mouse on the References section of Project explorer and select "Add Reference ...", then find the assembly named "System" in the .NET section, and add it to your project.
You will also need to add the following statement to the top of your source code:
using System.Net;
[/edit]
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
Thanks for your answer! I apologize for my mistake ...
I've done all everything you said and actually decrease errors. However there are still 5 errors relating some wrong commands. For example, some of errors are:
"The type or name 'Stream' could not be found (are you missing a using directive or an assembly reference?)"
"The type or name 'Bitmap' could not be found (are you missing a using directive or an assembly reference?)"
"The type or name 'MemoryStream' could not be found (are you missing a using directive or an assembly reference?)"
Do you know how experiencing this error?
|
|
|
|
|
Eventually was missing the command using System.IO;
So the following 2 errors are gone
"The type or name 'Stream' could not be found (are you missing a using directive or an assembly reference?)".
"The type or name 'MemoryStream' could not be found (are you missing a using directive or an assembly reference?)".
Now the problem is with the command Bitmap
|
|
|
|
|
Synodiporos wrote: Now the problem is with the command Bitmap
All of these classes are described in MSDN. Here is the link to Bitmap [^]; the others are easy to find.
And, more usefully, MSDN comes in many languages other than American.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
Thanks for your advice Richard!
I have fix all the mistakes and now the program is running. The problem now is that i take a warning in this line:
while ((read = stream.Read(buffer, total, 1000)) != 0)
The warning says “Specified argument was out of the range of valid values.
Parameter name: size”
I changed the size of the variable to a larger but the problem remains. I do not know what else should I do now ...
|
|
|
|
|
Forget it! Once I found a solution for this ...
int bytesToRead = 1000;
while ((read = stream.Read(buffer, total, bytesToRead)) != 0)
{
total += read;
bytesToRead -= read;
}
Perhaps the variable "bytesToRead" should be reduced in the loop ...
|
|
|
|
|
I am coming again to the thread to asked you a little help.
I have make all necessary changes and now my program is running without any errors or warnings. But i can not see the image! Specifically I created a form with a button and a pictureBox. I want when I click the button to save the image and display it in the pictureBox.
Why cannot display the image? Here is my example:
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string sourceURL = "http://192.168.1.xxx:xx/videostream.cgi";
byte[] buffer = new byte[200000];
int read, total = 0;
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(sourceURL);
req.Credentials = new NetworkCredential("Admin", "xxxx");
WebResponse resp = req.GetResponse();
Stream stream = resp.GetResponseStream();
int bytesToRead = 1000;
while ((read = stream.Read(buffer, total, bytesToRead)) != 0)
{
total += read;
bytesToRead -= read;
}
Bitmap bmp = (Bitmap)Bitmap.FromStream(stream);
bmp.Save("C:\\image.jpg");
pictureBox1.Image = bmp;
}
private void pictureBox1_Click(object sender, EventArgs e)
{
}
Can you help me in this?
|
|
|
|
|
What type of object is pictureBox1 and are you sure that the statement
pictureBox1.Image = bmp; sets the object correctly? Note that the bmp object gets destroyed as soon as the button1_Click() function terminates.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
Thanks for your help!
Now, I can get the image from the camera ...
|
|
|
|
|
While it's not a solution to your question, I'd like to point something out.
Any network address that begins with 192.168 is an address in a private network. What this means is that, only computers in that network may access other devices within it.
As such, it's entirely safe for me to say that the IP of the machine I'm typing on right now is 192.168.43.156 , and that the address of my gateway (the 'side' of the router that my pc can see) is 192.168.43.1
If I browse to a 'WhatsMyIp' type of website, the address returned is the IP that the 'other side' of my router has - the address that CAN be seen from anyone connected to the web. This address is NOT safe to share publicly.
See here for more on private networks: http://en.wikipedia.org/wiki/Private_network[^]
|
|
|
|
|
Hi Guys,
Is there any way to validate a socket descriptor before doing any IO on it?
~ Vikram S
|
|
|
|
|
What do you mean by validate, against what criteria?
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
For example I am holding an client socket connected with some server. The server goes down or network goes down. Before doing any action I want to know is the socket in good state.
|
|
|
|
|
Ah, the age old problem.
Look, when two asynchronous processes are communicating things can go wrong at any moment. Even if there was a great way for you to check to see if the socket is in a good state, 1/2 microsecond later it could go bad so you'd still have to handle the "bad state" case when you access the socket connection. Just because it was in a good state an instant ago doesn't mean it still is, that's the nature of asynchronous communications and networks.
The falicy is expecting orderly things to happen in a disorderly world. Better to concentrate your efforts in dealing with the "error conditions", trying to communicate with the socket and discovering it's in a "bad state" by handling the failure returns, timeouts, etc. Handle the "disorderly shutdown" cases and you'll discover that the "orderly shutdown" cases fall out nicely.
|
|
|
|
|
Besides the other reply note as well that there is no way to insure that a socket is working without sending something (reading will not work.)
|
|
|
|
|
I have 3 buttons on a dialod with tab stop property = false, sometimes if I click all buttons in random order a hover effect (round blue) comes around the 2 buttons simultaneouly. It don't disappear even after mouse is not on any button. I think It should not come. Can you please suggest any workaround?
|
|
|
|
|
Never seen or heard this behaviour described before. It does sound very strange. I just tried a win32 dialog-based project (compiled and run under win7 x64 home premium) yet was still unable to replicate this behaviour.
Can you show the DialogProc that you are using? Mine is below. (I have 5 buttons, only respond to the clicking of two of them)
BOOL CALLBACK DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg)
{
case WM_INITDIALOG:
return TRUE;
case WM_CLOSE:
EndDialog(hwndDlg, 0);
return TRUE;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDC_BTN_QUIT:
EndDialog(hwndDlg, 0);
return TRUE;
case IDC_BTN_TEST:
MessageBox(hwndDlg, "You clicked \"Test\" button!", "Information", MB_ICONINFORMATION);
return TRUE;
}
}
return FALSE;
}
|
|
|
|
|
Using WinInet -
I tried to send some data to login a website.But its server need to check my cookie at the same time.If the cookie is not match,this login action will be faild.I called the CHttpFile::AddRequest to add my cookie into the http header,than called CHttpFile::SendRequest.But the server return an error message.I holded this msg to google.Someone said this meens to your cookie in error.An internet friend said can not add in cookie into header to send,but use the CInternetSession::SetCookie.
SetCookie?How to use it?Or in other way can help me?
PS:I am a Chinese.My English is not well.But I need your help.Thank!
MFC VC C++ WinInet
|
|
|
|
|
I can't figure out how to do template specialization. I have the following situation:
template <class T>
ContainerClass
{
T pop() { void push(T) {
T findNextItem(TypeEnum myType);
template <> MySpecificClass findNextItem<MyspecificClass>(TypeEnum myType);
};
Only the specific class (MySpecificClass) has the TypeEnum, so I want to write a function that's specific for that version of the class.
How do I do that? I get error messages along the lines of:
error: explicit specialization in non-namespace scope
error: expected ‘;’ at end of member declaration
error: declaration of
error: conflicts with previous declaration
modified 5-Mar-12 17:02pm.
|
|
|
|
|
The following is getting close - but I get an error complaining of multiple definitions, both pointing to the implementation of the function??
Note: By the way I'm using gcc on Ubuntu.
template <class T>
ContainerClass
{
T pop() { void push(T) {
T findNextItem(TypeEnum myType);
};
template <>
MySpecificClass ContainerClass<MySpecificClass >::findNextItem(TypeEnum myType)
{
}
modified 5-Mar-12 18:26pm.
|
|
|
|
|
The following compiles for me.
I'm using VC 2010.
enum TypeEnum {};
class MySpecificClass {};
template <class T>
class ContainerClass
{
T pop() {}
void push(T) {}
T findNextItem(TypeEnum myType);
};
template <>
MySpecificClass ContainerClass<MySpecificClass>::findNextItem(TypeEnum myType)
{
return MySpecificClass();
}
int _tmain(int argc, _TCHAR* argv[])
{
ContainerClass<int> a;
ContainerClass<MySpecificClass> b;
return 0;
}
|
|
|
|
|
I need to add a software update check to my program. I started by writing a winsock function and making a call to my web site to get a document using
trncpy_s( sendbuf, 1024, "GET /updates/siteAdministrator.exe.txt HTTP/1.0\r\n", strlen( "GET /updates/siteAdministrator.exe.txt HTTP/1.0\r\n") );
strncat_s( sendbuf, 1024, "Host: www.website.com\r\n", strlen( "Host: www.website.com\r\n" ) );
strncat_s( sendbuf, 1024, "\r\n", strlen( "\r\n" ) );
My Question 1 is:
Without downloading other pre-fabricated programs that does this, or trying to reverse engineer other programs,
What would you recommend that I connect to just to get going at a beginners level. Perhaps a web service that returns the current version, or just a text file that contains the current version, and what information should I return?
If it's a text file, what recommended format would you suggest?
Question 2:
I'm looking for a way to resolve a URL to an IP Address, for this part of my winsock. I don't want to hard code it, because inside my LAN, I use private numbers, and outside my LAN is public numbers.
sTargetDevice.sin_family = PF_INET;
sTargetDevice.sin_addr.s_addr = inet_addr( ipAddress );
sTargetDevice.sin_port = htons((unsigned short) ipPort);
|
|
|
|
|
jkirkerx wrote: I'm looking for a way to resolve a URL to an IP Address...
Are you referring to gethostbyname() ?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|