【MediaKit】WPF項目中 調用網路攝影機拍照的開發包

來源:互聯網
上載者:User

標籤:http   io   ar   os   sp   for   strong   檔案   on   

今天遇到一個 人事的項目,項目中需要調用網路攝影機給員工照相。如何解決這個問題呢?

介紹一個開發包給你,MediaKit。論壇裡頭的人都說好,但是黑兔覺得大家好才是真的好。你不妨試試~

第一步:添加WPFMediaKit.DLL 檔案到項目中

第二步:把WPFMediaKit.dll檔案引用進來。

  步驟 右擊引用—>添加引用—>瀏覽選項卡—>選擇WPFMediaKit.dll檔案所在的位置.

第三步:在視窗頂端加入如下代碼(注意不要該意記)就像using一個類樣。

xmlns:WPFMediaKit="clr-namespace:WPFMediaKit.DirectShow.Controls;assembly=WPFMediaKit"

<Window x:Class="IXiahe.Photos"        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"        Title="Photos" Height="300" Width="300"       xmlns:WPFMediaKit="clr-namespace:WPFMediaKit.DirectShow.Controls;assembly=WPFMediaKit"        WindowStartupLocation="CenterScreen" Loaded="loaded">

第四步:添加VideoCaptureElement控制項 用來顯示一個預覽的畫面 (需要手寫,因為工具箱沒有這個控制項)

 <StackPanel>            <ComboBox Name="cb" SelectionChanged="cb_SelectionChanged"/> <!--選網路攝影機-->            <WPFMediaKit:VideoCaptureElement Height="200" Name="vce"/> <!--預覽畫面-->            <Button Height="50" x:Name="btnCapture" Content="拍照" Click="btnCapture_Click"/> <!--拍照按鈕-->        </StackPanel>  
    第五步: 接下來就是後台代碼
private void Window_Loaded(object sender, RoutedEventArgs e)        {            cb.ItemsSource = MultimediaUtil.VideoInputNames;            if (MultimediaUtil.VideoInputNames.Length > 0)            {                cb.SelectedIndex = 0;//第0個網路攝影機為預設網路攝影機            }            else            {                MessageBox.Show("電腦沒有安裝任何可用網路攝影機");            }        }        private void cbCameras_SelectionChanged(object sender, SelectionChangedEventArgs e)        {            captureElement.VideoCaptureSource = (string)cbCameras.SelectedItem;        }        /// <summary>        /// 拍照        /// </summary>        private void btnCapture_Click(object sender, RoutedEventArgs e)        {            //captureElement. 怎麼抓取高清的原始映像                       RenderTargetBitmap bmp = new RenderTargetBitmap(                (int)captureElement.ActualWidth,                (int)captureElement.ActualHeight,                96, 96, PixelFormats.Default);            //為避免抓不全的情況,需要在Render之前調用Measure、Arrange            //為避免VideoCaptureElement顯示不全,需要把            //VideoCaptureElement的Stretch="Fill"            captureElement.Measure(captureElement.RenderSize);            captureElement.Arrange(new Rect(captureElement.RenderSize));            bmp.Render(captureElement);            //這裡需要建立一個流以便儲存網路攝影機拍攝到的圖片。
            //當然,可以使檔案流,也可以使記憶體流。
            BitmapEncoder encoder = new JpegBitmapEncoder();            encoder.Frames.Add(BitmapFrame.Create(bmp));            encoder.Save(ms);            captureElement.Pause();        }        /// <summary>        /// 重拍        /// </summary>        private void btnanew_Click(object sender, RoutedEventArgs e)        {            captureElement.Play();        }        /// <summary>        /// 確定        /// </summary>        private void btnOK_Click(object sender, RoutedEventArgs e)        {            CaptureData = ms.ToArray();            ms.Dispose();            DialogResult = true;        }

【MediaKit】WPF項目中 調用網路攝影機拍照的開發包

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.