【问题标题】:Spire.Barcode printing barcode from stringSpire.Barcode 从字符串打印条形码
【发布时间】:2018-09-24 06:25:22
【问题描述】:

我无法解决我的条形码问题。我在 Excel 中传递我的文件中的字符串,例如 51453125312453。我在我的模型中使用 Spire.Barcode,就像这样

private void GenerateBarcode()
    {
        BarcodeSettings st = new Spire.Barcode.BarcodeSettings();
        st.Code128SetMode = Spire.Barcode.Code128SetMode.Auto;
        //st.Data = Ilosc.ToString("F6") + "*" + Partia;
        st.TextFont = new System.Drawing.Font("Arial", 16);
        st.ShowTopText = false;
        st.ShowTextOnBottom = true;
        st.ImageWidth = 100;
        Spire.Barcode.BarCodeGenerator bg = new Spire.Barcode.BarCodeGenerator(st);
        HeaderBarcode = bg.GenerateImage().ToString();
        //bg.GenerateImage();
    }

和我的字符串

private string headerBarcode;
    public string HeaderBarcode
    {
        get
        {
            return headerBarcode;
        }
        set
        {
            if (headerBarcode != value)
            {
                headerBarcode = value;
                GenerateBarcode();
                NotifyPropertyChanged(nameof(HeaderBarcode));
            }
        }
    }

在我的打印预览中有这个 System.Drawing.Bitmap 而不是条形码。你能帮我解决这个问题吗?

【问题讨论】:

    标签: c# barcode barcode-printing


    【解决方案1】:

    您在这一行的错误:

    HeaderBarcode = bg.GenerateImage().ToString();
    

    GenerateImage() - 返回位图,因此当您尝试将位图转换为字符串时,您会得到一个 System.Drawing.Bitmap 类的名称。

    您需要另存为图像并打开它。

    bg.GenerateImage().Save("Barcode.png");
    System.Diagnostics.Process.Start("Barcode.png");
    

    【讨论】:

    • 好的,但是这个字符串 HeaderBarcode 呢?这个条形码应该在哪里生成这个字符串?
    猜你喜欢
    • 2019-10-27
    • 1970-01-01
    • 1970-01-01
    • 2012-06-13
    • 1970-01-01
    • 1970-01-01
    • 2010-09-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多