Last post Apr 30, 2011 05:03 AM by HeartattacK
Apr 29, 2011 05:16 PM|fadi-ft|LINK
Hellow my friends ...
I am working on enable my web application to start and view my webcam I reach a good point, sort of, but still facing manay problems, I am going to paste the code that I have obtained over the net
<%@ Page Language="VB" ContentType="image/jpeg" %>
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Drawing" %>
<%@ Import Namespace="System.Drawing.Drawing2D" %>
<%@ Import Namespace="System.Drawing.Imaging" %>
<%@ Import Namespace="System.Net" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script language="VB" runat="server">
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
'Jpeg compression quality
Dim nQuality As Short = 45
'Shout a picture from my webcam
Dim cam As CAMSERVERLib.Camera = New CAMSERVERLib.CameraClass()
Dim picture As Byte() = DirectCast(cam.GrabFrame(nQuality), Byte())
'Add the hour to the jpeg picture
Dim ms As New MemoryStream(picture)
Dim bmp As New Bitmap(ms)
Dim g As Graphics = Graphics.FromImage(bmp)
Dim strDate As String = DateTime.Now.ToLongDateString() & " - " & DateTime.Now.ToLongTimeString()
Dim drawFormat As New StringFormat()
drawFormat.Alignment = StringAlignment.Center
g.DrawString(strDate, New Font(FontFamily.GenericSansSerif, 12), New SolidBrush(Color.Black), New RectangleF(1, 1, 320, 240), drawFormat)
g.DrawString(strDate, New Font(FontFamily.GenericSansSerif, 12), New SolidBrush(Color.White), New RectangleF(0, 0, 320, 240), drawFormat)
Dim icf As ImageCodecInfo() = ImageCodecInfo.GetImageEncoders()
Dim encps As New EncoderParameters(1)
Dim encp As New EncoderParameter(System.Drawing.Imaging.Encoder.Quality, CLng(nQuality))
encps.Param(0) = encp
bmp.Save(Response.OutputStream, icf(1), encps)
<form id="form1" runat="server">
<img src="~/Default.aspx" width="320" height="240" />
Just the Problem: I am having the error: ERROR GrabFrame() I have search over the net with no result or any solutions for my problem Please if anyone have any idea about this could he or she help me regards
Apr 29, 2011 05:26 PM|HeartattacK|LINK
Are you sure the code you got was for an ASP.NET Application or a Windows Desktop Application? I don't know much about your CamServerLib, but from what I can tell, the code looks like it will only capture images from the webcam on the SERVER's machine -
not from user's browsers. Your browser page's would need some sort of plugin to be able to capture images from users visiting your sight. Plugins would include Silverlight, Flash or some other ActiveX Plugin. Server side code won't be able to capture from
the user's webcam.
I would recommend you look into Silverlight if you wish to capture images from your users' webcams.
Apr 29, 2011 05:36 PM|fadi-ft|LINK
Hello Heartattack and thanks for your reply,
yes I got it for ASP.NET application. the Idea of my projec is enable users to run their cameras through my page and then capture an image so I can compare it with another saved in my database.
when I run the application the webcame lights so it means that it is working after that ERROR Grabframe happen. at this level i need to run it in anyway does not matter if it just work at server-side only
Apr 29, 2011 05:55 PM|HeartattacK|LINK
Your code suggests that the image taken will be from the Server's webcam, not the user's. The code may work for you during testing if your server and client are the same machine, but as soon as you test the website from any remote machine, your code will
not work. I would again recommend you use Silverlight to gain access to the user's webcam.
Apr 29, 2011 06:02 PM|fadi-ft|LINK
I appreciate your advise but realy I dont have any idea or background about Silverlight, if you would help I would be very thankful
currently i dnot need to test remotly
Apr 29, 2011 06:11 PM|HeartattacK|LINK
ASP.NET is a server side technology that takes your code and generates HTML. The HTML is sent to the user's browser. No ASP.NET code can ever "execute" on the user's browser. The ASP.NET code execution ends when the response is sent. As such, ASP.NET code
has no access to the user's webcam. Your code will ONLY capture images from the SERVER's webcam. Say your server (which runs your website) is on machine A. John views your website in FireFox on his machine. If John clicks the capture button, the saved image
will NOT be John's image- it will be of whatver is in front of machine A. When you're "testing" it locally, your server and browser are on the same machine. That's the ONLY reason it may appear to work. But that is completely useless for any website. If you
stick with that code and try to fix it, your website will work properly from only one machine (the machine running the website).
Watch this video:
It shows how to access the webcam using Silverlight so you would be able to get John's image in the example above.
Apr 29, 2011 06:21 PM|fadi-ft|LINK
OK ... it seems that Silverlight is my only sol ... I have watched the video and it is very very good ... but, as i have just told you above, I have no idea how to deal with SL and how to work with it through VS ... is SL like a library we reference it in
the application or what. I have downloaded a setup file of SL with 5.99 mb from silverligh site .... HELP !!
Apr 30, 2011 05:03 AM|HeartattacK|LINK
Go to www.silverlight.net andview some of the getting started tutorials. You can use VS 2010 to develop Silverlight applications. The 6MB download is essentially the Silverlight runtime. Users of your website will
need that installed. It's like Flash. This site is focussed on ASP.NET. www.silverlight.net is our sister site focusing on Silverlight development. There are plenty of tutorials, videos etc. there and that should be all you need. When you learn how to create
a basic SL application, the video I linked to previously should guide you in capturing images from a user's webcam.