2016年2月22日 星期一

[EmguCV] 開啟彩色影像

成果























程式碼
&ltWindow x:Class="Basic_Program.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:Basic_Program"
        mc:Ignorable="d"
        Title="MainWindow" Height="350" Width="525"&gt
    &ltGrid&gt
        &ltButton x:Name="button" Content="Open" HorizontalAlignment="Left" Margin="411,150,0,0" VerticalAlignment="Top" Width="75" Click="button_Click"/&gt
        &ltImage x:Name="image" HorizontalAlignment="Left" Height="268" Margin="22,24,0,0" VerticalAlignment="Top" Width="371"/&gt
    &lt/Grid&gt
&lt/Window&gt

using Emgu.CV;
using Emgu.CV.Structure;
using System;
using System.Windows;
using System.Windows.Forms;

namespace Basic_Program
{
    /// 
    /// MainWindow.xaml 的互動邏輯
    /// 
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void button_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog Openfile = new OpenFileDialog();
            if (Openfile.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                Image My_Image = new Image(Openfile.FileName);
                image.Source = Emgu.CV.WPF.BitmapSourceConvert.ToBitmapSource(My_Image);
            }
        }
    }
}

沒有留言:

張貼留言