所以我遇到了这个问题,即 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;
.......
}