Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8280551
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T09:43:06+00:00 2026-06-08T09:43:06+00:00

note I am new in Wpf > I have project that decode qr code

  • 0

note I am new in Wpf >
I have project that decode qr code by using opencv library throw web cam >
and it running successfully

now I wanna to using this project in new Wpf project >
after adding new wpf project and make reference to WinForms application >

and this my simple code to open WinForm >

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

by ruining give me this exception >

The type initializer for ‘Emgu.CV.CvInvoke’ threw an exception.>

what can I do for solve this

C# code

 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();
    }}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T09:43:07+00:00Added an answer on June 8, 2026 at 9:43 am

    If you want to host WinForm in WPF, you need to use host control System.Windows.Forms.Integration.WindowsFormsHost

    WPF provides many controls with a rich feature set. However, you may
    sometimes want to use Windows Forms controls on your WPF pages. For
    example, you may have a substantial investment in existing Windows
    Forms controls, or you may have a Windows Forms control that provides
    unique functionality.

    Example code

    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);
    }
    

    Check =>
    http://msdn.microsoft.com/en-us/library/ms751761.aspx

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I bind XML file to WPF TreView using this code: XmlDocument XMLdoc = new
this code is correct?? String note = text.txt; FileWriter file = new FileWriter(note); Scanner
I have created a new table including a column note. The default is varchar(255)
Note that the _src inherit IQueryable<U> and V inherit new() ; I wrote the
C#, .NET 4.0, VS2010. New to WPF. I have a ComboBox on my MainWindow.
I'm very new to this WPF technology, I started with a sticky note application
I have a Console Application that references the WPF dlls. I instantiated and attempted
I have a WPF application that has just one button. When the button is
I have a WPF control that I would like to overlay onto a WinForms
I am new to WPF - and painfully aware of it. I have unsuccessfully

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.