常见问题:Web 应用中的 TBarCode
如何将条码图像流式传输到浏览器(客户端)?
如何将条码图像流式传输到浏览器(客户端)?
使用 TBarCode,可以将条码图像(例如基于 GET 或 POST 参数)以流的形式返回给客户端。
您可以看看我们的在线条码生成器,我们正是这样实现的。
以下网址会将一张条码图像(编码了单词 "TBarCode" 的 Data Matrix)以流的形式返回给浏览器:http://barcode.tec-it.com/barcode.ashx
请将以下代码片段作为 TBarCode .NET 在 ASP.NET 中的起点:
// first adjust the barcode properties of the myBarcode object (class Barcode) // then calculate the width and height of the code in Pixels (sample available on request) // then write the barcode image as stream to the browser as follows Bitmap image = myBarcode.DrawBitmap(width, height); image.SetResolution(dpi, dpi); Response.Clear(); Response.ContentType = "image/gif"; image.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Gif); HttpContext.Current.ApplicationInstance.CompleteRequest(); image.Dispose();
该 SDK 安装包中(在示例文件夹内)包含 Barcode Generator ASP.NET Web 应用程序,它利用 TBarCode .NET Barcode Generator 程序集,能够将图像流式传输到浏览器。该应用程序同样可以安装在您自己的 Web 服务器上。