#geshi(C#,number){{ using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes;
namespace OpenCvSharpWithWpf {
/// <summary>
/// MainWindow.xaml の相互作用ロジック
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
// OpenCvSharp をダウンロードする。
// http://code.google.com/p/opencvsharp/
// Open CV にパスが通っていることを確認する。
// .NET 4.0 の WPF のプロジェクトを作る。
// OpenCvSharp.dll と OpenCvSharp.Extensions.dll への参照を追加する。
// (このプロジェクトファイルでは OpenCvSharpDlls 内にファイルをコピーして、参照を追加した。)
// ここから下のコードを追加する。
// 普段は using OpenCvSharp; とかしてる。
var openFileDialog = new Microsoft.Win32.OpenFileDialog();
if (openFileDialog.ShowDialog() != true) { return; }
OpenCvSharp.IplImage loadedIplImage;
try { loadedIplImage = new OpenCvSharp.IplImage(openFileDialog.FileName); }
catch { return; }
var srcIplImage = new OpenCvSharp.IplImage(30, 30, loadedIplImage.Depth, loadedIplImage.NChannels);
OpenCvSharp.Cv.Resize(loadedIplImage, srcIplImage);
Func<System.Windows.Controls.Image> getImageFunc = new Func<System.Windows.Controls.Image>(() =>
{
var iplImage = srcIplImage.Clone();
var bitmapSource = OpenCvSharp.Extensions.BitmapSourceConverter.ToBitmapSource(iplImage);
var wpfImage = new System.Windows.Controls.Image() { Stretch = System.Windows.Media.Stretch.None };
wpfImage.Source = bitmapSource;
return wpfImage;
});
var horizontalStackPanel = new System.Windows.Controls.StackPanel() { Orientation = System.Windows.Controls.Orientation.Horizontal };
var verticalStackPanel = new System.Windows.Controls.StackPanel() { Orientation = System.Windows.Controls.Orientation.Vertical };
var uniformGrid = new System.Windows.Controls.Primitives.UniformGrid() { Rows = 2, Columns = 3 };
var wrapPanel = new System.Windows.Controls.WrapPanel() { Width = srcIplImage.Width * 2 };
for (int i = 0; i < 5; i++)
{
horizontalStackPanel.Children.Add(getImageFunc());
verticalStackPanel.Children.Add(getImageFunc());
uniformGrid.Children.Add(getImageFunc());
wrapPanel.Children.Add(getImageFunc());
}
var windowContent = new System.Windows.Controls.Primitives.UniformGrid() { Rows = 2, Columns = 2 };
windowContent.Children.Add(horizontalStackPanel);
windowContent.Children.Add(verticalStackPanel);
windowContent.Children.Add(uniformGrid);
windowContent.Children.Add(wrapPanel);
this.Content = windowContent;
this.SizeToContent = System.Windows.SizeToContent.WidthAndHeight;
}
}
} }}