wpf字符转条码

        private BitmapSource GetImageSouce(Bitmap bitmap)
        {
            BitmapSource img;
            IntPtr hBitmap;
            hBitmap = bitmap.GetHbitmap();
            img = Imaging.CreateBitmapSourceFromHBitmap(
                hBitmap,
                IntPtr.Zero,
                Int32Rect.Empty,
                BitmapSizeOptions.FromEmptyOptions());
            return img;
        }
        //点击转换
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            var writer = new BarcodeWriter
            {
                Format = BarcodeFormat.CODE_128, // 指定条码格式
                Options = new EncodingOptions
                {
                    Height = 60, // 指定条码高度
                }
            };
            if (textBox1.Text == "")
                return;
            var result = writer.Write(textBox1.Text);
            image1.Source = GetImageSouce(result);
        }

你可能感兴趣的:(C#,wpf)