I have a server listening for connections. Client connects and both start streaming webcam images. This works fine as long as there is only one client connected(runni ng as a Thread). When another client connects, the new thread starts streaming as well. The camera is accessed in a mutual exclusive way by locking which fails some times and I get AccessViolation Exception. Below is the code executing in the thread.
The scenario is like this : One person sitting at a help desk and doing video conferencinf with multiple clients. Server hosted at the helpdesk itself. -
try {
-
bytes = new byte[(ConfConsole.CAP.Stride * ConfConsole.CAP.Height)];
-
lock (lok) {
-
ptr = ConfConsole.CAP.GetBitMap(); //static object accessed by threads
-
Marshal.Copy(ptr, bytes, 0, bytes.Length); //error here sometimes
-
if (ptr != IntPtr.Zero) {
-
Marshal.FreeCoTaskMem(ptr);//error here sometimes
-
ptr = IntPtr.Zero;
-
}
-
}
-
bmp = (Bitmap)Utils.CopyDataToBitmap(
-
bytes, ConfConsole.CAP.Width, ConfConsole.CAP.Height);
-
bmp.RotateFlip(RotateFlipType.RotateNoneFlipY);
-
jpg = Utils.ResizeBitmap(bmp, 320, 240);
-
bmp.Dispose();
-
} catch (Exception e) {
-
l.log("error in capturing image + data : " + e.Message);
-
}
-
-
//code ripped from net
-
public static Bitmap CopyDataToBitmap(byte[] data, int width, int height) {
-
Bitmap bmp = new Bitmap(width, height, PixelFormat.Format24bppRgb);
-
//Create a BitmapData and Lock all pixels to be written
-
BitmapData bmpData = bmp.LockBits(
-
new Rectangle(0, 0, bmp.Width, bmp.Height),
-
ImageLockMode.WriteOnly, bmp.PixelFormat);
-
//Copy the data from the byte array into BitmapData.Scan0
-
Marshal.Copy(data, 0, bmpData.Scan0, data.Length);
-
//Unlock the pixels
-
bmp.UnlockBits(bmpData);
-
//Return the bitmap
-
return bmp;
-
}
-
-
0 2220 Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Joakim Rylander |
last post by:
Hi all,
I need to create a public booth where people can look at themselves in a
webcam and snap a picture which will be seen on a webpage. The backend is
easy, it's the webcam part that I have problems with...
Could you recommend the best way to capture a Webcam picture from .NET?
Do I need device specific drivers or is there a standardized way to do it?
Any recommended brand of Webcam?
|
by: Christy |
last post by:
Does anyone have any idea how i can begin to start programming an automatic image capture from a webcam by just using .NET?
Thanks!
|
by: CodeMayhem |
last post by:
Hey fellow coders,
I need help in integrating webcam capturing into a program written i
C#. the camera will face the user and when he or she clicks th
"capture" button, the camera should take the picture and display it o
the program. before clicking the capture button, the user should b
able to see the camera's view so that the user can adjust the positio
of the camera in order to get a good picture.
Hope someone can help me on this.
|
by: Nikolay Petrov |
last post by:
I need to capture frames from my webcam using a windows service.
I've found some sample code on how to use thw VfW API, but I have two
major problems:
1. The sample code uses picturebox to preview and grab images. I want
to do it in formless windows service, so I need to capture frames
without displaying anything.
2. All samples I've found are using Windows Clipboard. They call the
API function which grabs as frame and put it in...
|
by: tony obrien |
last post by:
Hi,
I have written a Class Library in VB.net which provides Props/Meths to a
caller to hide the uglinesses of a TCP message protocol between a Client
and a Server.
All this works just fine.
Now I am trying to develop a LOAD TESTER app which spawns lotso' threads
each with this capability to bang the server.
| |
by: indhu |
last post by:
Hi all, am new to the VB forum.
Anyway, i need a help from u all. i am developing project.where i am using some kind of webcam. capture image thru webcam by cliking capture button in the form. i ve to pick a color from the image using color picker tool. then this tool will drop the color in the next image (predefined image)other side of the form. then i will choose the lip area alone to change color using some predefined colors. any...
|
by: debasisdas |
last post by:
This program checks if webcam is available, if available then capture video and displays in picture box.
Add this code to the general module (.BAS file)
----------------------------------------------------------------------
Public Const ws_child As Long = &H40000000
Public Const ws_visible As Long = &H10000000
Global Const WM_USER = 1024
Global Const wm_cap_driver_connect = WM_USER + 10
Global Const wm_cap_set_preview = WM_USER + 50
|
by: Steve |
last post by:
Hi All
I have a VB.net 2005 windows forms application which uses webcam to take
photos of staff members etc for use within the application
All works fine if an external webcam is used
The problem I have is when clients have a laptop with built in webcam
The first time I connect to the capture drivers all works well. If I try to
|
by: O.B. |
last post by:
When using Marshal to copy data from a byte array to the structure
below, only the first byte of the "other" array is getting copied from
the original byte array. What do I need to specify to get
Marshal.PtrToStructure to copy the all the data into the "other"
array?
unsafe public struct DeadReckoning
{
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |