日期:2014-05-20  浏览次数:21084 次

[二维条码问题][PDF417]关于二维码编码及解码问题!
最近手头有个项目,需要用到PDF417格式的二维码

请问哪位做过这方面的东西,提供一些资料,谢谢!

CSDN上有个PDF417的.NET类,不知道怎么生成图片,给出使用方法也可以!

再次感谢!

------解决方案--------------------
有钱人,一出手就是200;
------解决方案--------------------
友情帮顶
------解决方案--------------------
如果你下到的代码,只有
SupportClass.cs
Pdf417lib.cs

那么就这样操作

1:新建一个winform项目,默认有了一个form1,然后把前面的两个cs添加进去
2:把Pdf417lib.cs里面的main()函数改个名字,比如叫main1()
3:把这个函数段拷贝到form1中
C# code

public static Bitmap GenerateBitmap(string barcodeText, int hscale, int vscale) 
{ 
Pdf417lib pd = new Pdf417lib(); 
pd.setText(barcodeText); 
pd.Options = Pdf417lib.PDF417_INVERT_BITMAP; 
pd.paintCode(); 
Bitmap bitmap = new Bitmap(pd.BitColumns * hscale, pd.CodeRows * vscale); 
Graphics g = Graphics.FromImage(bitmap); 
sbyte[] bits = pd.OutBits; 
 
int cols = (pd.BitColumns - 1) / 8 + 1; 
 
int row = -1;  
int bitcol = 0; 
for(int i=0; i < bits.Length; ++i) 
{ 
if ((i % cols) == 0) 
{ 
row++; 
bitcol = 0; 
} 
int value = bits[i]; 
for(int j = 7; j >= 0; j--) 
{ 
int mask = (int) Math.Pow(2, j); 
if((value & mask) != 0) 
g.FillRectangle(Brushes.White, bitcol * hscale, row * vscale, hscale, vscale); 
else 
g.FillRectangle(Brushes.Black, bitcol * hscale, row * vscale, hscale, vscale); 
bitcol++; 
if(bitcol == pd.BitColumns) 
break; 
} 
} 
g.Dispose(); 
 
return bitmap; 
}

------解决方案--------------------
up
------解决方案--------------------
C# code

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Drawing;
using System.Drawing.Design;
using System.Drawing.Drawing2D;
using System.Drawing.Printing;
using System.Drawing.Imaging;
using System.IO;

public partial class _Default : System.Web.UI.Page
{
    private string CreateCheckCodeString()
    { //定义用于验证码的字符数组
        char[] AllCheckCodeArray ={ '0','1','2','3','4','5','6','7','8','9','A','B','C',
        'D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W',
        'X','Y','Z','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q',
        'r','s','t','u','v','w','x','y','z'};
        //定义验证码字符串
        string randomcode = "";
        Random rd = new Random();
        //生成4位验证码字符串
        for (int i = 0; i < 8; i++)
            randomcode += AllCheckCodeArray[rd.Next(AllCheckCodeArray.Length)];
        return randomcode;
    }
    //生成验证码图片
    protected void Page_Load(object sender, EventArgs e)
    {
        //定义图片的宽度
        int ImageWidth = 80;
        //定义图片高度
        int ImageHeigh = 25;
        //定义字体,用于绘制文字
        Font font = new Font("Arial", 10, FontStyle.Bold);
        //定义画笔,用于绘制文字
        Brush brush = new SolidBrush(Color.Black);
        //定义钢笔,用于绘制干扰线
        Pen pen1 = new Pen(Color.FromArgb(255, 100, 100), 0);//这里也可以直接获得一个现有的color对象如:Color.Gold.我是为了美观所以定义和下面一样
        Pen pen2 = new Pen(Color.FromArgb(255, 100, 100), 0);//这里根据ARGB值定义获得了一个color对象
        //创建一个图像
        Bitmap BitImage = new Bitmap(ImageWidth, ImageHeigh);
        //从图像获取一个绘画面
        Graphics graphics = Graphics.FromImage(BitImage);
        //清除整个绘图画面并用颜色填充
        graphics.Clear(ColorTranslator.FromHtml("#F0F0F0"));//这里从HTML代码获取color对象
        //定义文字的绘制矩形区域
        RectangleF rect = new RectangleF(5, 2, ImageWidth, ImageHeigh);
        //定义一个随机数对象,用于绘制干扰线
        Random rand = new Random();
        //生成两条横向的干扰线
        for (int i = 0; i < 2; i++)
        {
            //定义起点
            Point p1 = new Point(0, rand.Next(ImageHeigh));
            //定义终点
            Point p2 = new Point(ImageWidth, rand.Next(ImageHeigh));
            //绘制直线
            graphics.DrawLine(pen1, p1, p2);
        }
        //生成两条纵向的干扰线
        for (int i = 0; i < 2; i++)
        {
            //定义起点
            Point p1 = new Point(rand.Next(ImageWidth), 0);
            //定义终点
            Point p2 = new Point(rand.Next(ImageWidth), ImageHeigh);
            //绘制直线
            graphics.DrawLine(pen2, p1, p2);
        }
        //绘制验证码文字
        graphics.DrawString(CreateCheckCodeString(), font, brush, rect);
        //保存图片为gif格式
        BitImage.Save(Response.OutputStream, ImageFormat.Gif);
        //释放对象
        graphics.Dispose();
        BitImage.Dispose();
        _Default a = new _Default();
        Session["xyz"] = a.CreateCheckCodeString();
    }
}

------解决方案--------------------
http://download.csdn.net/down/376426/andy1016
------解决方案--------------------
呵,我来学习