c# - 如何将条码图像插入 PrintDialog?

标签 c#

我有这个程序,我可以在其中打印一些关于托盘(物流)的信息,我需要向其中添加条形码。我环顾四周,发现 http://www.codeproject.com/Articles/20823/Barcode-Image-Generation-Library看起来确实很有前途。

我添加了 .dll 引用并添加了以下代码:

using BarcodeLib;

// Create barcode size 100, 100 with the ordernumber in type EAN13
    Barcode b = new Barcode(order.OrderNr);
    b.Encode(TYPE.EAN13, order.OrderNr, 100, 100);

现在我需要知道的是如何将它添加到页面上的特定位置。我目前添加文本的方式看起来像这样:

private void PrintLabel(PrintPageEventArgs e, Graphics g)
{
    marginTop = 8;
    marginLeft = 5;
    int row = marginTop;

    g.DrawString("Order nr: ", headerTitleFont, blackText, marginLeft, row);
    g.DrawString(order.OrderNr, headerTextFont, blackText, marginLeft + 120, row);
    row += 22;
    ...etc...

    Barcode b = new Barcode(order.OrderNr);
    b.Encode(TYPE.EAN13, order.OrderNr, 100, 100);
    // Print the label b here on position: marginLeft, row
}

最佳答案

根据given documentation , Encode 返回 System.Drawing.Image

这非常方便,因为它允许您使用以下方法简单地将其绘制成图形:

Barcode b = new Barcode(order.OrderNr);
Image barcodeImage = b.Encode(TYPE.EAN13, order.OrderNr, 100, 100);

g.DrawImage(barcodeImage, marginLeft, row);

关于c# - 如何将条码图像插入 PrintDialog?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33755727/

相关文章:

c# - 使用传输安全和客户端证书时无法将数据发布到 WCF 休息服务

c# - 在 MySql (PhpMyadmin) 中根据条件将数据插入字段中

C# 锯齿状数组 : outside the bounds of the array issue

c# - 我有一个表,它有一个由三列组成的主键。我如何索引这个表?

c# - 是否可以像扩展 .net 框架类一样扩展 .net 框架命名空间?

c# - 是否可以在 C# 中使用 getter/setter 模板?

c# - .Net存在: chicken and eggs?

c# - 如何在 C# 中通过网络发送任意对象

c# - .NET Core 自访问查询过滤器

c# - 类数组