wpf mediakit 攝像頭截圖


在用VideoCaptureElement的過程中,不知道怎么獲得攝像頭的截圖,糾結了整整一天,

最終在下面的網站上找到了答案,哈哈。(困的都不清醒的大腦,讓我耐下心來看英文,上天還是很優待我的)

例子截圖:

XAML:

<Window x:Class="Fish.AccountBook.View.Test.CameraWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="CameraWindow" Height="200" Width="300"
        xmlns:WPFMediaKit="clr-namespace:WPFMediaKit.DirectShow.Controls;assembly=WPFMediaKit">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="30" />
            <RowDefinition Height="auto" />
        </Grid.RowDefinitions>
        <StackPanel Orientation="Horizontal">
            <Button Name="button1" Content="截圖" Height="23"  Width="75" Click="button1_Click" />
        </StackPanel>
        <WPFMediaKit:VideoCaptureElement x:Name="m_VideoCaptureElement" Grid.Row="1" />
    </Grid>
</Window>

CS:

    public partial class CameraWindow : Window
    {
        public CameraWindow()
        {
            InitializeComponent();

            string[] inputNames = MultimediaUtil.VideoInputNames;
            m_VideoCaptureElement.VideoCaptureSource = inputNames[0];
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            RenderTargetBitmap bmp = new RenderTargetBitmap((int)m_VideoCaptureElement.ActualWidth, (int)m_VideoCaptureElement.ActualHeight, 96, 96, PixelFormats.Rgb24);
            bmp.Render(m_VideoCaptureElement);
            BitmapEncoder encoder = new JpegBitmapEncoder();
            encoder.Frames.Add(BitmapFrame.Create(bmp));
            string now = DateTime.Now.Year + "" + DateTime.Now.Month + "" + DateTime.Now.Day + "" + DateTime.Now.Hour + "" + DateTime.Now.Minute + "" + DateTime.Now.Second;
            string filename = "D:\\" + now + "pic.jpg";
            FileStream fstream = new FileStream(filename, FileMode.Create);
            encoder.Save(fstream);
            fstream.Close();


        }
    }

 

 

參考:http://wpfmediakit.codeplex.com/

參考:http://wpfmediakit.codeplex.com/discussions/287507


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM