Vote count:
0
Ok, I have a program that is playing a video from a live ip camera, lets call this "AppVideo". I have another program that is going to play this video in a webForm, lets call this program "Play Video".
The way I want to play this video in Play Video is save an image from AppVideo every few seconds and display the new image.
So in AppVideo, I'm saving every new frame to a filestream.
Now what I'm trying to do is take the new image from that filestream and save it in an image folder. This is done in Play Video's page Video.aspx. Then in viewer.aspx the image is displayed.
here is the code for Video.aspx
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Services;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
using System.Drawing;
namespace PlayVideo
{
public partial class Video : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string saveTo = @"C:where to save image";
FileStream writeStream = new FileStream(saveTo, FileMode.Create, FileAccess.ReadWrite);
using (FileStream fs = File.Open(@"C:filestream is saved", FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite))
{
ReadWriteStream(fs, writeStream);
}
Response.Clear();
Response.TransmitFile("~/images/test.jpg");
}
// readStream is the stream you need to read
// writeStream is the stream you want to write to
private void ReadWriteStream(Stream readStream, Stream writeStream)
{
int Length = 256;
Byte[] buffer = new Byte[Length];
int bytesRead = readStream.Read(buffer, 0, Length);
// write the required bytes
while (bytesRead > 0)
{
writeStream.Write(buffer, 0, bytesRead);
bytesRead = readStream.Read(buffer, 0, Length);
}
readStream.Close();
writeStream.Close();
}
}
}
Then here is the code for viewer.aspx:
<head id="Head1" runat="server">
<title></title>
<script type="text/javascript" src="refreshImagePage.js"></script>
</head>
<body>
<form id="form1" runat="server">
<div style="height: 60px" id="div1">
<img src="/Video.aspx" id="the_image" alt="" />
<script type="text/javascript" language="javascript">
// alert(1)
function refreshImage() {
// alert(2);
window.location.reload();
// objIMG = document.getElementById('the_image');
// objIMG.src = objIMG.src.substr(0, objIMG.src.indexOf('&nocache=')); +'&nocache=' + Math.random();
// alert(3);
}
$(document).ready(function () {
setInterval(updateImage, 5000);
})
</script>
</div>
</form>
</body>
</html>
if you notice, in the javascript on viewer.aspx I am refreshing the entire page and commented out refreshing just the image. Refreshing the image wasn't working and I think it is because of how the image is being saved; the function that saves the image from the filestream is in the page load so it only saves the newest image when the page is loaded. I have been working on this for around 3 weeks and can't think of anything else to try. Any ideas? This way works right now, but I don't like that it refreshes the entire page.
Can someone help me with a better way to save images in WebForms?
Aucun commentaire:
Enregistrer un commentaire