2009-04-08 21:05:13 UTC
I don't know if u still need it, but just in case, i wrote a
procedure: DrawBarcodeImage It worked pretty well for me. Here is the code and a Main function to taste it.
//by Eduardo Serrano
protected Image DrawBarcodeImage(Pdf417lib pd,int scale_x,int scale_y)
{
Bitmap bmp;
sbyte[] out_Renamed;
int cols;
int tmp;
int x = 0, y = -1;
Color c;
out_Renamed = pd.OutBits;
cols = (pd.BitColumns - 1) / 8 + 1;
bmp = new Bitmap(pd.BitColumns * scale_x , (pd.outBits.Length / cols) * scale_y );
for (int k = 0; k < out_Renamed.Length; ++k)
{
if ((k % cols) == 0)
{
y++;
x = 0;
}
tmp = (out_Renamed[k] & 0xff) | 0x100;
for (int j = 0; j < 8; j++)
{
if ((tmp & (0x80 >> j)) == 0)
{
c = Color.Black;
}
else
{
c = Color.White;
}
for (int xx = 0; xx < scale_x; xx++)
{
for (int yy = 0; yy < scale_y; yy++)
{
bmp.SetPixel(x * scale_x + xx, y * scale_y + yy, c);
}
}
x++;
if (x == pd.BitColumns)
break;
}
}
return bmp;
}
[STAThread]
public static void Main(System.String[] args)
{
Pdf417lib pd = new Pdf417lib();
pd.CodeRows = 90;
pd.CodeColumns = 30;
String texto = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
pd.setText(texto+texto+texto );
pd.CodeRows = 90;
pd.CodeColumns = 30;
pd.Options = Pdf417lib.PDF417_INVERT_BITMAP;
pd.paintCode();
System.IO.StreamWriter pr = new System.IO.StreamWriter(new System.IO.FileStream("mips.ps", System.IO.FileMode.Create));
int cols = (pd.BitColumns - 1) / 8 + 1;
pr.WriteLine("/Times findfont\n12 scalefont setfont\n100 80 moveto\n(A PDF417 example.)show");
pr.WriteLine("stroke\n100 100 translate\n" + pd.BitColumns / 2.0 + " " + pd.CodeRows * 3 / 2.0 + " scale");
pr.Write(pd.BitColumns + " " + pd.CodeRows + " 1 [" + pd.BitColumns + " 0 0 " + (-pd.CodeRows) + " 0 " + pd.CodeRows + "]{<");
sbyte[] out_Renamed = pd.OutBits;
for (int k = 0; k < out_Renamed.Length; ++k)
{
if ((k % cols) == 0)
pr.WriteLine();
pr.Write(System.Convert.ToString((out_Renamed[k] & 0xff) | 0x100, 16).Substring(1).ToUpper());
}
pr.WriteLine("\n>}image\nshowpage");
pr.Close();
pd.DrawBarcodeImage(pd,1,1).Save("mips.bmp", ImageFormat.Bmp);
}