RXC
RXC

Reputation: 1233

Webcam Component in C# XNA

I am using the old webcam component file to stream a webcam video feed onto a Texture2D object.

I need help with the code as it is old and visual studio 2010 and XNA 4 does not recognize some of the syntax.

In the method BufferCB, the two lines that modify color are outdated. It says the "The type or namespace name Color does not exist in the namespace Microsoft.XNA.Framwork.Graphics (are you missing an assembly reference?)".

Here is the function:

public int BufferCB(double SampleTime, IntPtr pBuffer, int BufferLen)
{
    byte[] bgrData = new byte[BufferLen];
    Marshal.Copy(pBuffer, bgrData, 0, BufferLen);
    Color[] colorData = new Color[BufferLen / 3];
    for (int i = 0; i < colorData.Length; i++)
    {
       colorData[i] = new Microsoft.Xna.Framework.Graphics.Color(bgrData[3 * i + 2], bgrData[3 * i + 1], bgrData[3 * i]);
    }
       this.videoTexture.SetData<Microsoft.Xna.Framework.Graphics.Color>(colorData);
            return 0;
 }

The line in the for loop and the line of code right after the for loop have the Color problem.

Also, how do I instantiate this class in my game class?

Any help would be great. Thanks

Upvotes: 1

Views: 465

Answers (1)

Justin Skiles
Justin Skiles

Reputation: 9513

The error describes literally the exact problem.

Color is part of the Microsoft.Xna.Framework namespace in XNA 4. See: http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.color%28v=xnagamestudio.35%29.aspx

You can instantiate Color using 4 constructors.

Color color = new Color(r, g, b); (where rgb are red/green/blue ints)

Color color = new Color(r, g, b); (where rgb are red/green/blue floats)

Color color = new Color(r, g, b, a); (where rgb are red/green/blue/alpha ints)

Color color = new Color(r, g, b, a); (where rgb are red/green/blue/alpha floats)

Upvotes: 2

Related Questions