C # WPF uses Zxing to generate two-dimensional code ImageSource

Source: Internet
Author: User

1, download the zxing on the http://zxingnet.codeplex.com/site. NET third-party libraries

2, the download after decompression can see there are different. NET version of the DLL file, referencing the correct DLL in your project

3. Then reference the System.Drawing assembly in your project

4. In the window where you need to generate the QR code, add the code

// Reclaiming Objects [DllImport ("gdi32")] Static extern int DeleteObject (IntPtr o);
        /** * Create two-dimensional code images*/        PrivateImageSource Createqrcode (String content,intWidthintheight) {encodingoptions options;//contains some settings for encoding, size, etc.Barcodewriter Write =NULL;//used to generate two-dimensional code, the corresponding barcodereader to decodeOptions =Newqrcodeencodingoptions {disableeci=true, CharacterSet="UTF-8", Width=width, Height=height, Margin=0            }; Write=NewBarcodewriter (); Write. Format=Barcodeformat.qr_code; Write. Options=options; Bitmap Bitmap=write.            Write (content); INTPTR IP=bitmap.            Gethbitmap (); BitmapSource BitmapSource=System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap (IP, IntPtr.Zero, Int32rect.empty,            System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions ());            DeleteObject (IP); returnBitmapSource; }

5, call Createqrcode can complete the imagesource generation of the QR code, and then use the image to display

C # WPF uses Zxing to generate two-dimensional code ImageSource

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.