您的位置:首页 > 其它

用Barcode生成条形码图片

2014-03-24 11:23 465 查看
使用第三方类库: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;
}
 


  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐