转换C#代码以在WPF中工作 [英] convert c# code to work in wpf
本文介绍了转换C#代码以在WPF中工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在做一个项目,我需要转换c#代码才能在wpf环境中工作.
代码是:
Hi,
I am working on a project and I need to convert c# code to work in wpf environment.
The code is :
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Emgu.CV;
using Emgu.Util;
using Emgu.CV.Structure;
using Emgu.CV.CvEnum;
namespace capture
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Capture cap;
private HaarCascade haar;
private void Form1_Load(object sender, EventArgs e)
{
// passing 0 gets zeroth webcam
cap = new Capture(0);
// adjust path to find your xml
haar = new HaarCascade("haarcascade_mcs_mouth.xml");
}
private void timer1_Tick(object sender, EventArgs e)
{
using (Image<Bgr, byte> nextFrame = cap.QueryFrame())
{
if (nextFrame != null)
{
// there''s only one channel (greyscale), hence the zero index
//var faces = nextFrame.DetectHaarCascade(haar)[0];
Image<Gray, byte> grayframe = nextFrame.Convert<Gray, byte>();
var faces =
grayframe.DetectHaarCascade(
haar, 1.4, 4,
HAAR_DETECTION_TYPE.DO_CANNY_PRUNING,
new Size(nextFrame.Width / 8, nextFrame.Height / 8)
)[0];
foreach (var face in faces)
{
//int x = face.rect.Height;
//nextFrame.Draw(face.rect, new Bgr(100, double.MaxValue, 0), 3);
//label1.Text = face.rect.Top.ToString();
label1.Text = face.rect.Height.ToString();
}
pictureBox1.Image = nextFrame.ToBitmap();
}
}
}
}
}
有没有人可以帮助我将其转换为可在wpf环境中使用的功能?
[edit]添加代码块以提高可读性-OriginalGriff [/edit]
Is there anyone help me to convert it to work in wpf environment
[edit]Code block added to improve readability - OriginalGriff[/edit]
推荐答案
将其转换为WPF的唯一方法是手工(手动)进行.
您还可以使用WPF/Winform互操作性按原样呈现整个表单,但这有点丑陋,当然也不是纯粹的WPF.如果您决定走这条路,我会将Winform表单放入其自己的程序集中,并以这种方式使用它.
Google是您的朋友.
The only way to convert it to WPF is to do it by hand (manually).
You could also use the WPF/Winform Interoperability to bring the whole form over as is, but that''s kinda ugly, and is not, of course, pure WPF. If you do decide to go this route, I would put the Winform form into its own assembly, and use it that way.
Google is your friend.
这篇关于转换C#代码以在WPF中工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文