0

私はWpfの初心者です> opencvライブラリを使用してqrコードをデコードするプロジェクトがあり、Webカムをスローします>そしてそれは正常に実行されてい ます

このプロジェクトを新しい Wpf プロジェクトで使用したい > 新しい wpf プロジェクトを追加し、winFrom アプリケーションへの参照を作成した後 >

そして、これはwinfromを開くための私の簡単なコードです>

public void runnow(){
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new CameraCapture.cameraCapture()); }

台無しにすることで、この例外を私に与えてください >

「Emgu.CV.CvInvoke」の型初期化子が例外をスローしました。 >

これを解決するために私は何ができますか

C# コード

 public partial class CameraCapture : Form
 {

Capture capture;
    bool Capturing;
    Bitmap bimap;
    private Reader reader;
    private Hashtable hint;
    libAES libEncryption = new libAES();
    string Mykey = "";
   public static String dataDecrypted="";


    public CameraCapture()
    {
        InitializeComponent();
    }

    private void Mains(object sender, EventArgs arg) // Start function main to encode Qr code
    {
        Image<Bgr, Byte> image = capture.QueryFrame();
        if (image != null)
        {
            bimap = image.ToBitmap();
            pictureBox1.Image = bimap;
            reader = new QRCodeReader();
            hint = new Hashtable();   //  Add some elements to the hash table. There are no  duplicate keys, but some of the values are duplicates.
            hint.Add(DecodeHintType.POSSIBLE_FORMATS, BarcodeFormat.QR_CODE);
            RGBLuminanceSource source = new RGBLuminanceSource(bimap, bimap.Width, bimap.Height);  //This class is used to help decode images from files which arrive as RGB data from* Android bitmaps. It does not support cropping or rotation.
            BinaryBitmap img = new BinaryBitmap(new GlobalHistogramBinarizer(source));
            Result result = null;
            try
            {
                result = reader.decode(img, hint);
                dataDecrypted = libEncryption.Decrypt(result.Text, Mykey);

            }
            catch
            {
                dataDecrypted = "";
            }
            if (result == null)
            {
                label1.Text = " no decode";

            }
            else
            {

                label4.Text = result.Text;
                label1.Text = dataDecrypted;

                capture.Dispose();

            }
        }


    } // end function Main


    private void btnStart_Click(object sender, EventArgs e)
    {
        if (capture == null)
        {
            try
            {
                capture = new Capture(); // **the exption thown here**
            }
            catch (NullReferenceException exception)
            {
                MessageBox.Show(exception.Message);
            }
        }
        if (capture != null)
        {
            if (Capturing)
            {
                btnStart.Text = "Start Capture";
                Application.Idle -= Mains;
            }
            else
            {
                btnStart.Text = "Stop Capture";
                Application.Idle += Mains;
            }
            Capturing = !Capturing;
        }
    }
    private void Release()
    {
        if (capture != null)
            capture.Dispose();
    }}
4

1 に答える 1

0

WPF で WinForm をホストする場合は、ホスト コントロール System.Windows.Forms.Integration.WindowsFormsHost を使用する必要があります。

WPF は、豊富な機能セットを備えた多くのコントロールを提供します。ただし、WPF ページで Windows フォーム コントロールを使用したい場合もあります。たとえば、既存の Windows フォーム コントロールに多額の投資を行っている場合や、独自の機能を提供する Windows フォーム コントロールを使用している場合があります。

サンプルコード

private void Window_Loaded(object sender, RoutedEventArgs e) 
{
// Create the interop host control.
System.Windows.Forms.Integration.WindowsFormsHost host =
    new System.Windows.Forms.Integration.WindowsFormsHost();

// Create the MaskedTextBox control.
MaskedTextBox mtbDate = new MaskedTextBox("00/00/0000");

// Assign the MaskedTextBox control as the host control's child.
host.Child = mtbDate;

// Add the interop host control to the Grid
// control's collection of child controls.
this.grid1.Children.Add(host);
}

チェック=> http://msdn.microsoft.com/en-us/library/ms751761.aspx

于 2012-07-24T15:19:42.707 に答える