rdlc 显示条码
来源:互联网 发布:顶级域名购买 编辑:程序博客网 时间:2024/06/03 01:40
/// <summary>
/// 生成条码图片
/// </summary>
/// <param name="strSource"></param>
/// <returns></returns>
public static Bitmap GetCode39(string strSource)
{
int x = 5; //左邊界
int y = 5; //上邊界
int WidLength = 2; //粗BarCode長度
int NarrowLength = 1; //細BarCode長度
int BarCodeHeight = 50; //BarCode高度
int intSourceLength = strSource.Length;
string strEncode = "010010100"; //編碼字串 初值為 起始符號 *
string AlphaBet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%*"; //Code39的字母
string[] Code39 = //Code39的各字母對應碼
{
/**//* 0 */ "000110100",
/**//* 1 */ "100100001",
/**//* 2 */ "001100001",
/**//* 3 */ "101100000",
/**//* 4 */ "000110001",
/**//* 5 */ "100110000",
/**//* 6 */ "001110000",
/**//* 7 */ "000100101",
/**//* 8 */ "100100100",
/**//* 9 */ "001100100",
/**//* A */ "100001001",
/**//* B */ "001001001",
/**//* C */ "101001000",
/**//* D */ "000011001",
/**//* E */ "100011000",
/**//* F */ "001011000",
/**//* G */ "000001101",
/**//* H */ "100001100",
/**//* I */ "001001100",
/**//* J */ "000011100",
/**//* K */ "100000011",
/**//* L */ "001000011",
/**//* M */ "101000010",
/**//* N */ "000010011",
/**//* O */ "100010010",
/**//* P */ "001010010",
/**//* Q */ "000000111",
/**//* R */ "100000110",
/**//* S */ "001000110",
/**//* T */ "000010110",
/**//* U */ "110000001",
/**//* V */ "011000001",
/**//* W */ "111000000",
/**//* X */ "010010001",
/**//* Y */ "110010000",
/**//* Z */ "011010000",
/**//* - */ "010000101",
/**//* . */ "110000100",
/**//*' '*/ "011000100",
/**//* $ */ "010101000",
/**//* / */ "010100010",
/**//* + */ "010001010",
/**//* % */ "000101010",
/**//* * */ "010010100"
};
strSource = strSource.ToUpper();
//實作圖片
Bitmap objBitmap = new Bitmap(((WidLength * 3 + NarrowLength * 7) * (intSourceLength + 2)) + (x * 2), BarCodeHeight + (y * 2));
Graphics objGraphics = Graphics.FromImage(objBitmap);
//宣告GDI+繪圖介面
//填上底色
objGraphics.FillRectangle(Brushes.White, 0, 0, objBitmap.Width, objBitmap.Height);
for (int i = 0; i < intSourceLength; i++)
{
//檢查是否有非法字元
if (AlphaBet.IndexOf(strSource[i]) == -1 || strSource[i] == '*')
{
objGraphics.DrawString("含有非法字元", SystemFonts.DefaultFont, Brushes.Red, x, y);
return objBitmap;
}
//查表編碼
strEncode = string.Format("{0}0{1}", strEncode, Code39[AlphaBet.IndexOf(strSource[i])]);
}
strEncode = string.Format("{0}0010010100", strEncode);
//補上結束符號 *
int intEncodeLength = strEncode.Length;
//編碼後長度
int intBarWidth;
for (int i = 0; i < intEncodeLength; i++)
//依碼畫出Code39 BarCode
{
intBarWidth = strEncode[i] == '1' ? WidLength : NarrowLength;
objGraphics.FillRectangle(i % 2 == 0 ? Brushes.Black : Brushes.White, x, y, intBarWidth, BarCodeHeight); x += intBarWidth;
}
return objBitmap;
}
public static byte[] BitmapToBytes(Bitmap Bitmap)
{
MemoryStream ms = null;
try
{
ms = new MemoryStream();
Bitmap.Save(ms, ImageFormat.Gif);
byte[] byteImage = new Byte[ms.Length];
byteImage = ms.ToArray();
return byteImage;
}
catch (ArgumentNullException ex)
{
throw ex;
}
finally
{
ms.Close();
}
}
dsDataBase.DSPrint.DTBarCodePrintDataTable dtBarCode = new DES.dsDataBase.DSPrint.DTBarCodePrintDataTable();
if (!material.Equals(string.Empty))
{
byte[] imgBytes = ComClass.Com.BitmapToBytes(ComClass.Com.GetCode39(material));// BitmapToBytes(bmp);
dsDataBase.DSPrint.DTBarCodePrintRow row = dtBarCode.NewDTBarCodePrintRow();
row.BarCodeStr = material;
row.PicData = Convert.ToBase64String(imgBytes);
dtBarCode.Rows.Add(row);
}
dTBarCodePrintBindingSource.DataSource = dtBarCode;
- rdlc 显示条码
- RDLC文用reportview显示
- RDLC 页脚 页码显示
- 采用本地RDLC报表进行一维条码的打印
- 报表ReportViewer显示图片--rdlc
- 报表ReportViewer显示图片--rdlc
- RDLC-Chart饼图上显示百分比
- rdlc 报表实现百分比显示
- 报表ReportViewer显示图片--rdlc
- 水晶报表显示条码设置
- VB显示条码扫描仪数据
- RDLC
- Rdlc
- CODE 128 条码打印类 实现条码打印、显示
- 用rdlc时显示图片问题
- [水晶报表]实现RDLC 网格显示
- 报表ReportViewer显示rdlc资源的图片
- 条码
- 职场“三好”吃力不讨好
- typedef PACKED struct字节对齐详解
- 数据库连接池。。 转载。。 待学习。
- hibernate中常见的Exception错误及解决方法
- JSP调用JavaBean在网页上动态生成柱状图
- rdlc 显示条码
- IUSR_和IWAM_计算机名帐户的用户名和密码
- web报表导出成XML文件
- 英语单词-中国特有词汇(一)
- 如何在填报表中使用自定义的下拉日历
- CPSR SPSR
- 浏览器的新功能
- 将DataTable转换成JSON字符串的函数
- SWI : 软件中断