zoukankan      html  css  js  c++  java
  • C#生成条形码

    转自:http://www.cnblogs.com/AspDotNetMVC/archive/2012/11/16/2767576.html

     1 static byte[] GetBarcode(int height, int width,BarcodeLib.TYPE type,
     2                                           string  code,out System.Drawing.Image image)
     3         {
     4             image=null;
     5             BarcodeLib.Barcode b = new BarcodeLib.Barcode();
     6             b.BackColor = System.Drawing.Color.White;
     7             b.ForeColor = System.Drawing.Color.Black;
     8             b.IncludeLabel = true;
     9             b.Alignment = BarcodeLib.AlignmentPositions.CENTER;
    10             b.LabelPosition = BarcodeLib.LabelPositions.BOTTOMCENTER;
    11             b.ImageFormat = System.Drawing.Imaging.ImageFormat.Jpeg;
    12             System.Drawing.Font font = new System.Drawing.Font("verdana",10f);
    13             b.LabelFont = font;
    14 
    15             b.Height = height;
    16             b.Width = width;
    17 
    18             image = b.Encode(type, code);
    19             SaveImage(image, Guid.NewGuid().ToString("N")+".png");
    20             byte[] buffer = b.GetImageData(SaveTypes.GIF);
    21             return buffer;
    22         }

    原博主的代码没有贴出保存图片的代码,现在加上

    static  void  BuildBarcode()
           {
               System.Drawing.Image image;
               int width=250, height=100;
               byte[] buffer = GetBarcode(height, width, 
                        BarcodeLib.TYPE.CODE128, "Avx-(13614)-vR", out image);
           }
     1  static byte[] GetBarcode(int height, int width,BarcodeLib.TYPE type,
     2                                           string  code,out System.Drawing.Image image)
     3         {
     4             image=null;
     5             BarcodeLib.Barcode b = new BarcodeLib.Barcode();
     6             b.BackColor = System.Drawing.Color.White;
     7             b.ForeColor = System.Drawing.Color.Black;
     8             b.IncludeLabel = true;
     9             b.Alignment = BarcodeLib.AlignmentPositions.CENTER;
    10             b.LabelPosition = BarcodeLib.LabelPositions.BOTTOMCENTER;
    11             b.ImageFormat = System.Drawing.Imaging.ImageFormat.Jpeg;
    12             System.Drawing.Font font = new System.Drawing.Font("verdana",10f);
    13             b.LabelFont = font;
    14 
    15             b.Height = height;
    16             b.Width = width;
    17 
    18             image = b.Encode(type, code);
    19             SaveImage(image, Guid.NewGuid().ToString("N")+".png");
    20             byte[] buffer = b.GetImageData(SaveTypes.GIF);
    21             return buffer;
    22         }
    23 
    24      private static void SaveImage(System.Drawing.Image image, string p)
    25         {
    26             //自动保存图片到指定目录中
    27             string stringfilename ="G:\" + p;
    28             image.Save(stringfilename, System.Drawing.Imaging.ImageFormat.Jpeg);
    29         }

    使用该方法还需要一个动态链接库:

    barcode.dll下载 

    生成的条形码:

     

  • 相关阅读:
    A very good site containing a lot of wonderful videos from Microsoft, List_of_GUI_testing_tools,
    java试用(3)awt,UI
    deletion of pointer to incomplete type 'A'; no destructor called
    windbg
    semaphore与Mutex
    Display a Web Page in a Plain C Win32 Applicatio
    java试用(1)hello world
    Linux opensshserver,
    Toggle hardware data/read/execute breakpoints programmatically
    RTThread RTOS
  • 原文地址:https://www.cnblogs.com/robinblogs/p/4485502.html
Copyright © 2011-2022 走看看