C
cody
So, we have these video cameras at work, that use motion jpegs to send
images. I am able to get the feed into a c# application if I am given
a jpeg page where the image updates when I click refresh. However,
there are also mjpeg pages, that run a lot smoother, and my
understanding is that these are essentially the same thing as doing a
web request for the jpeg really quickly. I can't get these to load up
in my application the same way, however. I will post my code below,
any suggestions on how to either
A)receive the jpegs much faster(changing my timer doesn't help), or
B)just receive the mjpeg feed directly into the app
are greatly appreciated.
namespace StreamTest
{
public partial class Form1 : Form
{
HttpWebRequest wreq;
HttpWebResponse wresp;
Stream mystream;
Bitmap bmp;
Timer time = new Timer();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
time.Interval = 50;
time.Tick += new EventHandler(time_Tick);
pictureBox1.Image = LoadPicture("url");
time.Enabled = true;
}
void time_Tick(object sender, EventArgs e)
{
pictureBox1.Image = LoadPicture("url");
}
private Bitmap LoadPicture(string url)
{
HttpWebRequest wreq;
HttpWebResponse wresp;
Stream mystream;
Bitmap bmp;
bmp = null;
mystream = null;
wresp = null;
try
{
wreq = (HttpWebRequest)WebRequest.Create(url);
wreq.Credentials = new NetworkCredential("guest",
"guest");
wresp = (HttpWebResponse)wreq.GetResponse();
if ((mystream = wresp.GetResponseStream()) != null)
bmp = new Bitmap(mystream);
}
finally
{
if (mystream != null)
mystream.Close();
if (wresp != null)
wresp.Close();
}
return (bmp);
}
private void button1_Click(object sender, EventArgs e)
{
this.Close();
}
private void button1_Click_1(object sender, EventArgs e)
{
this.Close();
}
}
}
images. I am able to get the feed into a c# application if I am given
a jpeg page where the image updates when I click refresh. However,
there are also mjpeg pages, that run a lot smoother, and my
understanding is that these are essentially the same thing as doing a
web request for the jpeg really quickly. I can't get these to load up
in my application the same way, however. I will post my code below,
any suggestions on how to either
A)receive the jpegs much faster(changing my timer doesn't help), or
B)just receive the mjpeg feed directly into the app
are greatly appreciated.
namespace StreamTest
{
public partial class Form1 : Form
{
HttpWebRequest wreq;
HttpWebResponse wresp;
Stream mystream;
Bitmap bmp;
Timer time = new Timer();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
time.Interval = 50;
time.Tick += new EventHandler(time_Tick);
pictureBox1.Image = LoadPicture("url");
time.Enabled = true;
}
void time_Tick(object sender, EventArgs e)
{
pictureBox1.Image = LoadPicture("url");
}
private Bitmap LoadPicture(string url)
{
HttpWebRequest wreq;
HttpWebResponse wresp;
Stream mystream;
Bitmap bmp;
bmp = null;
mystream = null;
wresp = null;
try
{
wreq = (HttpWebRequest)WebRequest.Create(url);
wreq.Credentials = new NetworkCredential("guest",
"guest");
wresp = (HttpWebResponse)wreq.GetResponse();
if ((mystream = wresp.GetResponseStream()) != null)
bmp = new Bitmap(mystream);
}
finally
{
if (mystream != null)
mystream.Close();
if (wresp != null)
wresp.Close();
}
return (bmp);
}
private void button1_Click(object sender, EventArgs e)
{
this.Close();
}
private void button1_Click_1(object sender, EventArgs e)
{
this.Close();
}
}
}