Tech Off Thread

8 posts

extending WPF/Avalon/XAML - webcam preview

Back to Forum: Tech Off
  • User profile image
    cosminb

    Hello C9ers,

    I'm having some trouble figuring out how to do this: I've developed a camera library in C++/CLI which I use further in C# apps. After making it accessible to Windows Forms and Direct3D, I want to give Avalon/WPF a try, but this is where I got a bit stuck (lack of proper information). As you can see from the thread's title, I want to achieve
    the same functionality that currently is given by MediaElement/MediaPlayer. I want to be able to output my webcam preview video to any Visual element in WPF. How do I do that? Do I need to subclass MediaElement? Or MediaPlayer? Or something else. And how do I customize it? I hope someone has an answer to this really soon, I'm
    betting my final year project on this.

    Thanks in advance,

    Cosmin.

    P.S. Also, I want to know if C++/CLI can be used to subclass the controls, or it has to be done in C#.

    I've tried several places to get this info, noone seems to care... I hope C9 will.

  • User profile image
    footballism

        As I know from your statement, you can use your C++/CLI library in Windows Forms application, then you can leverage upon crossbow technology to host WPF controls(MediaElement, or MediaPlayer) in your Windows Forms Applications.
        Crossbow is a peice of interoperating technology between Windows Forms and WPF, you can get more info from this blog.
        Hopefully this helps.

  • User profile image
    cosminb

    Actually what I'm trying to do is to target WPF, not Windows Forms. Windows Forms are already covered by my library.

    So this is what I want to implement in Avalon: I want to display the preview video (taken directly from the webcam) in a similar way to how MediaElement works. So I want to be able to preview inside various shapes, or in 3D (I've seen a sample in Hands-On-Labs where there was a video file playing this way: inside shapes, and on the faces of a cube).

  • User profile image
    sashah

    Hi. This will be very useful. Any chance of a sample when you get it working??? thanks

  • User profile image
    cosminb

    Well, I just got some comments on this one, and it doesn't have a nice way around: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=296765&SiteID=1

    I will keep asking, until I get a clear view on how to do it.

    Edit:

    So far I've managed to get it to work in Windows Forms and Direct3D, if you're interested in some code.

  • User profile image
    GRiNSER

    why don't you try to put every image you get from the webcam into the Image object as a BitmapImage - i think wpf will be fast enough for this Wink
    there are libs out in the web which can find every webcam on your pc and send picture by picture from the cam to your app so that shouldn't be that difficult...

  • User profile image
    sashah

    Hi i think i may be able to do what you have suggested here. ONly problem im having is converting between a system.drawing.image to a system.windows.controls.image. cant find anything on web about it.

    can you help??

    thanks

    sash

  • User profile image
    footballism

    sashah wrote:

        ONly problem im having is converting between a system.drawing.image to a system.windows.controls.image. cant find anything on web about it.

    the following code snippet can do the trick:
    System.Drawing.Bitmap GdiBitmap = new System.Drawing.Bitmap(@"c:\temp\sample.jpg");
                            IntPtr hBitmap = bitmap.GetHbitmap();
                            System.Windows.Media.BitmapSource WpfBitmap = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmapbitmap(hBitmap, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
                            System.Windows.Controls.Image WpfImage = new System.Windows.Controls.Image();
                            WpfImage.Source = WpfBitmap;

    Sheva

Comments closed

Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation, please create a new thread in our Forums, or Contact Us and let us know.