0

所以我遇到了这个问题,即 qrcode 数据值需要是字符串类型,但我想添加一个随机指南作为值。我在坐下本应成为 guid 的字符串时遇到了一些麻烦。这是我的代码明智的:

二维码:

public void QRBarcode(string fileName)
    {
        BarcodeEngine engine = new BarcodeEngine();
        string outputFile = @"C:\QRCodeTesting\CreatedQRCode.pdf";
        int resolution = 300;

        using (RasterImage image = RasterImage.Create((int)(8.5 * resolution), (int)(11.0 * resolution), 1, resolution, RasterColor.FromKnownColor(RasterKnownColor.White)))
        {
            //Guid guidValue = new Guid();
            // Write two QR barcodes
            WriteBarcode(engine.Writer, image, QRBarcodeSymbolModel.Model1AutoSize, "need to add a guid", true);

        }
}

写二维码:

private void WriteBarcode(BarcodeWriter writer, RasterImage image, QRBarcodeSymbolModel symbolModel, string guidValue, bool topLeft)
    {
        // Create the barcode data
        QRBarcodeData barcode = BarcodeData.CreateDefaultBarcodeData(BarcodeSymbology.QR) as QRBarcodeData;
        barcode.SymbolModel = symbolModel;
        barcode.Value = guidValue;

         .......
    }
4

1 回答 1

0

一些早些时候发布了答案,但现在它被删除了,即使它是正确的。

Guid stringGUID = Guid.NewGuid().toString();
于 2013-05-24T16:57:34.010 回答