2013年1月10日 星期四

條碼製作

條碼產生的方法有許多種,常見的方法有:

  • 字型
  • 第三方服務:透過網址產生條碼圖片
  • 使用Libary:
    • Barcode Rendering Framework(barcoderender.codeplex.com)
      • Code 11,Code 25,Code 39,Code 93,Code 128
      • Code EAN 13,Code EAN 8
      • Code PDF417
      • Code QR

範例:

<p>private string GetBarcodeImage(string CODE,int BarHeight) <br>{<br>try<br>{<br>BarcodeSymbology b = BarcodeSymbology.CodeEan13;<br>Image img = BarcodeDrawFactory.GetSymbology(b).Draw(CODE, BarHeight,1);<br>return Convert.ToBase64String(UtilityUI.ImageToBuffer(img, System.Drawing.Imaging.ImageFormat.Jpeg));<br>}<br>catch (Exception ex)<br>{<br>return ex.ToString();<br>}<br>}<br></p> <p>/// <summary><br>/// 將 Image 轉換為 Byte 陣列。<br>/// </summary><br>/// <param name="Image">Image 。</param><br>/// <param name="imageFormat">指定影像格式。</param> <br>public static byte[] ImageToBuffer(Image Image, System.Drawing.Imaging.ImageFormat imageFormat)<br>{<br>if (Image == null) { return null; }<br>byte[] data = null;<br>using (MemoryStream oMemoryStream = new MemoryStream())<br>{<br>//建立副本<br>using (Bitmap oBitmap = new Bitmap(Image))<br>{<br>//儲存圖片到 MemoryStream 物件,並且指定儲存影像之格式<br>oBitmap.Save(oMemoryStream, imageFormat);<br>//設定資料流位置<br>oMemoryStream.Position = 0;<br>//設定 buffer 長度<br>data = new byte[oMemoryStream.Length];<br>//將資料寫入 buffer<br>oMemoryStream.Read(data, 0, Convert.ToInt32(oMemoryStream.Length));<br>//將所有緩衝區的資料寫入資料流<br>oMemoryStream.Flush();<br>}<br>}<br>return data;<br>}<br><br>//====<br></p><p><Image Name="ImgCode"></p><p>&nbsp; <Source>Database</Source></p><p>&nbsp; <Value>=System.Convert.FromBase64String(Fields!CODEIMG.Value)</Value></p><p>&nbsp; <MIMEType>image/png</MIMEType></p><p>&nbsp; <Style></p><p>&nbsp; &nbsp; <Border></p><p>&nbsp; &nbsp; &nbsp; <Style>None</Style></p><p>&nbsp; &nbsp; </Border></p><p>&nbsp; </Style></p><p></Image></p>

沒有留言:

張貼留言