gpt4 book ai didi

qr-code - 使用 CIQRCodeDescriptor initWithPayload : symbolVersion: maskPattern errorCorrectionLevel: 生成二维码

转载 作者:行者123 更新时间:2023-11-29 13:54:14 26 4
gpt4 key购买 nike

我正在尝试使用 CoreImage 生成二​​维码。我希望能够控制符号版本、屏蔽模式和纠错级别。

使用简单的“CIFilter filterWithName:”无法让您设置符号版本或掩码模式。

似乎唯一可行的方法是使用 CIQRCodeDescriptor - 使用“CIQRCodeDesciptor initWithPayload: symbolVersion: maskPattern: errorCorrectionLevel:”

有没有人能用这个方法成功生成二维码图片?

如果是这样,您能发布一个简单的完整示例吗?

最佳答案

为了能够使用 CIQRCodeDescriptor 你需要

  • 码字(模式+字符数+数据+终止符+填充)
  • 正确的符号版本(字符数版本;1-40)
  • 正确的掩码模式(带最小惩罚的掩码;0-7)

遵循“不同凡想”的示例。

Think Different

注意码字中的额外位

  • 与众不同:54 68 69 6E 6B 20 44 69 66 66 65 72 65 6E 74
  • 代码字:40 F5 46 86 96 E6 B2 04 46 96 66 66 57 26 56 E7 40 EC 11

码字构造在 nayuiki 中有解释。或在底部。

let codeword : [UInt8] = [0x40, 0xf5, 0x46, 0x86, 0x96, 0xe6, 0xb2, 0x04, 0x46, 0x96, 0x66, 0x66, 0x57, 0x26, 0x56, 0xe7, 0x40, 0xec, 0x11]
let data = Data(bytes: codeword, count: codeword.count)
if let descriptor = CIQRCodeDescriptor(payload: data, symbolVersion: 1, maskPattern: 4, errorCorrectionLevel: .levelL) {
if let image = imageFromBarcodeCodeDescriptor(descriptor)?.transformed(by: .init(scaleX: 10, y: 10)) {
let newImage = NSImage()
newImage.addRepresentation(NSCIImageRep(ciImage: image))
imageView1.image = newImage
}
}

func imageFromBarcodeCodeDescriptor(_ descriptor: CIBarcodeDescriptor) -> CIImage? {
let filter = CIFilter(name: "CIBarcodeGenerator", parameters: ["inputBarcodeDescriptor" : descriptor])
return filter?.outputImage
}

codeword construction

  1. Concatenate segments, add padding, make codewords

Notes:

The segment mode is always a 4-bit field.

The character count’s field width depends on the mode and version.

The terminator is normally four “0” bits, but fewer if the datacodeword capacity is reached.

The bit padding is between zero to seven “0” bits, to fill all unusedbits in the last byte.

The byte padding consists of alternating (hexadecimal) EC and 11 untilthe capacity is reached.

The entire sequence of data bits:01000000111101010100011010000110100101101110011010110010000001000100011010010110011001100110011001010111001001100101011011100111010000001110110000010001

The entire sequence of data codeword bytes (by splitting the bitstring into groups of 8 bits), displayed in hexadecimal: 40 F5 46 8696 E6 B2 04 46 96 66 66 57 26 56 E7 40 EC 11

关于qr-code - 使用 CIQRCodeDescriptor initWithPayload : symbolVersion: maskPattern errorCorrectionLevel: 生成二维码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57777948/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com