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