用Barcode生成条形码图片
使用第三方类库:BarcodeLib.dll
private BitmapImage GenerateBarcodeBitmap(string visitId) { BarcodeLib.Barcode barcode = new BarcodeLib.Barcode(); barcode.Alignment = BarcodeLib.AlignmentPositions.CENTER; barcode.IncludeLabel = true; barcode.LabelPosition = BarcodeLib.LabelPositions.BOTTOMCENTER; //b.RotateFlipType = RotateFlipType.; BarcodeLib.TYPE type = BarcodeLib.TYPE.CODE128; System.Drawing.Image image = barcode.Encode(type, visitId, Color.Black, Color.White, 200, 60); MemoryStream ms = new MemoryStream(); Bitmap bmp = new Bitmap(image); bmp.Save(ms, ImageFormat.Bmp); byte[] imgByte = new byte[ms.Length]; ms.Position = 0; ms.Read(imgByte, 0, Convert.ToInt32(ms.Length)); System.Windows.Media.Imaging.BitmapImage bitmapImage = new System.Windows.Media.Imaging.BitmapImage(); bitmapImage.BeginInit(); bitmapImage.StreamSource = new MemoryStream(imgByte); bitmapImage.EndInit(); return bitmapImage; }