QRCodeSegment Class
Represents a run of data encoded in one mode, with its own mode indicator and character count indicator, to choose the segments of a QR code yourself.
public sealed class QRCodeSegmentRemarks
QRCode.Create splits a text into segments by itself. Pass segments to QRCode.Create to choose them: to encode a text that the automatic segmentation keeps in one byte segment, to control the bytes of a byte segment, or to declare their encoding with an ECI designator.
Each segment costs a mode indicator and a character count indicator: 4 + 8 to 4 + 16 bits in a standard QR code, fewer in Micro QR and rMQR codes. A short segment can take more bits than the characters it saves.
Properties
| Name | Description |
|---|---|
| Bytes | Gets the bytes of a byte segment, or an empty value for the other modes. |
| EciAssignmentNumber | Gets the assignment number of an ECI designator, or null for the other modes. |
| Mode | Gets the mode of the segment. |
| Text | Gets the characters of a numeric, alphanumeric or Kanji segment, or null for a byte segment and an ECI designator. |
Bytes
QRCodeSegment.csGets the bytes of a byte segment, or an empty value for the other modes.
public ReadOnlyMemory<byte> Bytes { get; }Property value
Remarks
A segment created from a text by QRCodeSegment.CreateByte holds the UTF-8 bytes of the text.
EciAssignmentNumber
QRCodeSegment.csMode
QRCodeSegment.csText
QRCodeSegment.csMethods
| Name | Description |
|---|---|
| CreateAlphanumeric(string) | Creates a segment of digits, uppercase letters, and the characters $%*+-./:, in alphanumeric mode. |
| CreateByte(ReadOnlySpan<byte>) | Creates a segment of bytes, in byte mode. |
| CreateByte(string) | Creates a segment of a text encoded as UTF-8, in byte mode. |
| CreateEci(int) | Creates an ECI (Extended Channel Interpretation) designator, which declares the character encoding of the byte segments that follow it, such as QRCodeOptions.Utf8EciAssignmentNumber for UTF-8. |
| CreateKanji(string) | Creates a segment of kanji and kana, in Kanji mode (their Shift JIS codes). |
| CreateNumeric(string) | Creates a segment of digits, in numeric mode. |
CreateAlphanumeric(string)
QRCodeSegment.csCreates a segment of digits, uppercase letters, and the characters $%*+-./:, in alphanumeric mode.
public static QRCodeSegment CreateAlphanumeric(string text)Parameters
textstring- The characters.
Returns
QRCodeSegment A new QRCodeSegment instance.
Exceptions
ArgumentExceptiontextis empty or has a character that alphanumeric mode cannot encode.
CreateByte overloads
CreateByte(ReadOnlySpan<byte>)
QRCodeSegment.csCreates a segment of bytes, in byte mode.
public static QRCodeSegment CreateByte(ReadOnlySpan<byte> data)Parameters
dataReadOnlySpan<byte>- The bytes, copied.
Returns
QRCodeSegment A new QRCodeSegment instance.
Exceptions
ArgumentExceptiondatais empty.
CreateByte(string)
QRCodeSegment.csCreates a segment of a text encoded as UTF-8, in byte mode.
public static QRCodeSegment CreateByte(string text)Parameters
textstring- The text.
Returns
QRCodeSegment A new QRCodeSegment instance.
Exceptions
ArgumentExceptiontextis empty.
Remarks
Readers guess the encoding of the bytes unless an ECI designator declares it: precede the segment with CreateEci(QRCodeOptions.Utf8EciAssignmentNumber) when the text is not ASCII.
CreateEci(int)
QRCodeSegment.csCreates an ECI (Extended Channel Interpretation) designator, which declares the character encoding of the byte segments that follow it, such as QRCodeOptions.Utf8EciAssignmentNumber for UTF-8.
public static QRCodeSegment CreateEci(int assignmentNumber)Parameters
assignmentNumberint- The ECI assignment number, from 0 to 999999.
Returns
QRCodeSegment A new QRCodeSegment instance.
Exceptions
ArgumentOutOfRangeExceptionassignmentNumberis negative or greater than 999999.
Remarks
Only standard QR codes have ECI designators: Micro QR and rMQR codes reject them.
CreateKanji(string)
QRCodeSegment.csCreates a segment of kanji and kana, in Kanji mode (their Shift JIS codes).
public static QRCodeSegment CreateKanji(string text)Parameters
textstring- The characters.
Returns
QRCodeSegment A new QRCodeSegment instance.
Exceptions
ArgumentExceptiontextis empty or has a character that Kanji mode cannot encode.
Remarks
Kanji mode encodes the characters of the JIS X 0208 character set that every reader decodes the same way. It does not encode the half-width katakana, nor the characters that the variants of Shift JIS decode differently, such as ~ and -: encode them in byte mode.
CreateNumeric(string)
QRCodeSegment.csCreates a segment of digits, in numeric mode.
public static QRCodeSegment CreateNumeric(string digits)Parameters
digitsstring- The digits, from
0to9.
Returns
QRCodeSegment A new QRCodeSegment instance.
Exceptions
ArgumentExceptiondigitsis empty or has a character that is not a digit.