基本信息
源码名称:C# 生成条形码图片 示例
源码大小:0.17M
文件格式:.rar
开发语言:C#
更新时间:2018-06-06
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559
本次赞助数额为: 1 元×
微信扫码支付:1 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
条形码显示
条形码显示
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
//using gregn6Lib;
namespace BatchReport
{
public partial class Form1 : Form
{
// private GridppReport Report = new GridppReport();
private int fage = 1;
public Form1()
{
InitializeComponent();
// Report.LoadFromFile(AppDomain.CurrentDomain.BaseDirectory "Batch.grf");
}
private void button1_Click(object sender, EventArgs e)
{
fage = 2;
System.Drawing.Image image;
int width =200, height = 80;
string fileSavePath = AppDomain.CurrentDomain.BaseDirectory "BarcodePattern.jpg";
if (File.Exists(fileSavePath))
{
// File.Delete(fileSavePath);
GetBarcode(height, width, BarcodeLib.TYPE.CODE128, textBox1.Text, out image, fileSavePath);
}
else
{
GetBarcode(height, width, BarcodeLib.TYPE.CODE128, textBox1.Text, out image, fileSavePath);
}
FileStream filestream = new FileStream("BarcodePattern.jpg", FileMode.Open, FileAccess.Read);
pictureBox1.Image = Image.FromStream(filestream);
filestream.Close();
// filestream.Dispose();
}
public static void GetBarcode(int height, int width, BarcodeLib.TYPE type, string code, out System.Drawing.Image image, string fileSaveUrl)
{
try
{
image = null;
BarcodeLib.Barcode b = new BarcodeLib.Barcode();
b.BackColor = System.Drawing.Color.White;//图片背景颜色
b.ForeColor = System.Drawing.Color.Black;//条码颜色
b.IncludeLabel = true;
b.Alignment = BarcodeLib.AlignmentPositions.CENTER;
b.LabelPosition = BarcodeLib.LabelPositions.BOTTOMCENTER;
b.ImageFormat = System.Drawing.Imaging.ImageFormat.Jpeg;//图片格式
System.Drawing.Font font = new System.Drawing.Font("verdana", 10f);//字体设置
b.LabelFont = font;
b.Height = height;//图片高度设置(px单位)
b.Width = width;//图片宽度设置(px单位)
image = b.Encode(type, code);//生成图片
image.Save(fileSaveUrl, System.Drawing.Imaging.ImageFormat.Jpeg);
}
catch (Exception ex)
{
image = null;
}
}
private void label1_Click(object sender, EventArgs e)
{
}
private void button2_Click(object sender, EventArgs e)
{
if (fage == 2)
{
// string xmlData = "<Bill><Item><Batch>" textBox1.Text "</Batch></Item></Bill>";
//Report.LoadDataFromXML(xmlData);
// Report.PrintPreview(true);
}
else
{
MessageBox.Show("请先生成条形码后打印!");
}
// Report.Print(true);
}
}
}