本文整理汇总了Java中com.google.zxing.common.CharacterSetECI.getCharacterSetECIByName方法的典型用法代码示例。如果您正苦于以下问题:Java CharacterSetECI.getCharacterSetECIByName方法的具体用法?Java CharacterSetECI.getCharacterSetECIByName怎么用?Java CharacterSetECI.getCharacterSetECIByName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.zxing.common.CharacterSetECI
的用法示例。
在下文中一共展示了CharacterSetECI.getCharacterSetECIByName方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: encodeHighLevel
import com.google.zxing.common.CharacterSetECI; //导入方法依赖的package包/类
static String encodeHighLevel(String msg, Compaction compaction, Charset encoding) throws
WriterException {
StringBuilder sb = new StringBuilder(msg.length());
if (encoding == null) {
encoding = DEFAULT_ENCODING;
} else if (!DEFAULT_ENCODING.equals(encoding)) {
CharacterSetECI eci = CharacterSetECI.getCharacterSetECIByName(encoding.name());
if (eci != null) {
encodingECI(eci.getValue(), sb);
}
}
int len = msg.length();
int p = 0;
int textSubMode = 0;
if (compaction == Compaction.TEXT) {
encodeText(msg, 0, len, sb, 0);
} else if (compaction == Compaction.BYTE) {
bytes = msg.getBytes(encoding);
encodeBinary(bytes, 0, bytes.length, 1, sb);
} else if (compaction == Compaction.NUMERIC) {
sb.append('Ά');
encodeNumeric(msg, 0, len, sb);
} else {
int encodingMode = 0;
while (p < len) {
int n = determineConsecutiveDigitCount(msg, p);
if (n >= 13) {
sb.append('Ά');
encodingMode = 2;
textSubMode = 0;
encodeNumeric(msg, p, n, sb);
p += n;
} else {
int t = determineConsecutiveTextCount(msg, p);
if (t >= 5 || n == len) {
if (encodingMode != 0) {
sb.append('΄');
encodingMode = 0;
textSubMode = 0;
}
textSubMode = encodeText(msg, p, t, sb, textSubMode);
p += t;
} else {
int b = determineConsecutiveBinaryCount(msg, p, encoding);
if (b == 0) {
b = 1;
}
bytes = msg.substring(p, p + b).getBytes(encoding);
if (bytes.length == 1 && encodingMode == 0) {
encodeBinary(bytes, 0, 1, 0, sb);
} else {
encodeBinary(bytes, 0, bytes.length, encodingMode, sb);
encodingMode = 1;
textSubMode = 0;
}
p += b;
}
}
}
}
return sb.toString();
}
示例2: encode
import com.google.zxing.common.CharacterSetECI; //导入方法依赖的package包/类
public static QRCode encode(String content, ErrorCorrectionLevel ecLevel, Map<EncodeHintType,
?> hints) throws WriterException {
String encoding;
if (hints == null) {
encoding = null;
} else {
encoding = (String) hints.get(EncodeHintType.CHARACTER_SET);
}
if (encoding == null) {
encoding = DEFAULT_BYTE_MODE_ENCODING;
}
Mode mode = chooseMode(content, encoding);
BitArray headerBits = new BitArray();
if (mode == Mode.BYTE && !DEFAULT_BYTE_MODE_ENCODING.equals(encoding)) {
CharacterSetECI eci = CharacterSetECI.getCharacterSetECIByName(encoding);
if (eci != null) {
appendECI(eci, headerBits);
}
}
appendModeInfo(mode, headerBits);
BitArray dataBits = new BitArray();
appendBytes(content, mode, dataBits, encoding);
Version version = chooseVersion((headerBits.getSize() + mode.getCharacterCountBits
(chooseVersion((headerBits.getSize() + mode.getCharacterCountBits(Version
.getVersionForNumber(1))) + dataBits.getSize(), ecLevel))) + dataBits
.getSize(), ecLevel);
BitArray headerAndDataBits = new BitArray();
headerAndDataBits.appendBitArray(headerBits);
appendLengthInfo(mode == Mode.BYTE ? dataBits.getSizeInBytes() : content.length(),
version, mode, headerAndDataBits);
headerAndDataBits.appendBitArray(dataBits);
ECBlocks ecBlocks = version.getECBlocksForLevel(ecLevel);
int numDataBytes = version.getTotalCodewords() - ecBlocks.getTotalECCodewords();
terminateBits(numDataBytes, headerAndDataBits);
BitArray finalBits = interleaveWithECBytes(headerAndDataBits, version.getTotalCodewords()
, numDataBytes, ecBlocks.getNumBlocks());
QRCode qrCode = new QRCode();
qrCode.setECLevel(ecLevel);
qrCode.setMode(mode);
qrCode.setVersion(version);
int dimension = version.getDimensionForVersion();
ByteMatrix matrix = new ByteMatrix(dimension, dimension);
int maskPattern = chooseMaskPattern(finalBits, ecLevel, version, matrix);
qrCode.setMaskPattern(maskPattern);
MatrixUtil.buildMatrix(finalBits, ecLevel, version, maskPattern, matrix);
qrCode.setMatrix(matrix);
return qrCode;
}
示例3: encode
import com.google.zxing.common.CharacterSetECI; //导入方法依赖的package包/类
public static void encode(String s, ErrorCorrectionLevel errorcorrectionlevel, Map map, QRCode qrcode)
{
String s1;
Mode mode;
BitArray bitarray;
BitArray bitarray1;
int i;
BitArray bitarray2;
ByteMatrix bytematrix;
if (map == null)
{
s1 = null;
} else
{
s1 = (String)map.get(EncodeHintType.CHARACTER_SET);
}
if (s1 == null)
{
s1 = "ISO-8859-1";
}
mode = a(s, s1);
bitarray = new BitArray();
a(s, mode, bitarray, s1);
a(bitarray.getSize(), errorcorrectionlevel, mode, qrcode);
bitarray1 = new BitArray();
if (mode == Mode.BYTE && !"ISO-8859-1".equals(s1))
{
CharacterSetECI characterseteci = CharacterSetECI.getCharacterSetECIByName(s1);
if (characterseteci != null)
{
a(characterseteci, bitarray1);
}
}
a(mode, bitarray1);
if (mode == Mode.BYTE)
{
i = bitarray.getSizeInBytes();
} else
{
i = s.length();
}
a(i, qrcode.getVersion(), mode, bitarray1);
bitarray1.appendBitArray(bitarray);
a(qrcode.getNumDataBytes(), bitarray1);
bitarray2 = new BitArray();
a(bitarray1, qrcode.getNumTotalBytes(), qrcode.getNumDataBytes(), qrcode.getNumRSBlocks(), bitarray2);
bytematrix = new ByteMatrix(qrcode.getMatrixWidth(), qrcode.getMatrixWidth());
qrcode.setMaskPattern(a(bitarray2, errorcorrectionlevel, qrcode.getVersion(), bytematrix));
d.a(bitarray2, errorcorrectionlevel, qrcode.getVersion(), qrcode.getMaskPattern(), bytematrix);
qrcode.setMatrix(bytematrix);
if (!qrcode.isValid())
{
throw new WriterException((new StringBuilder()).append("Invalid QR code: ").append(qrcode.toString()).toString());
} else
{
return;
}
}
示例4: encode
import com.google.zxing.common.CharacterSetECI; //导入方法依赖的package包/类
public static void encode(String content, ErrorCorrectionLevel ecLevel, Hashtable hints,
QRCode qrCode) throws WriterException {
String encoding = hints == null ? null : (String) hints.get(EncodeHintType.CHARACTER_SET);
if (encoding == null) {
encoding = DEFAULT_BYTE_MODE_ENCODING;
}
// Step 1: Choose the mode (encoding).
Mode mode = chooseMode(content, encoding);
// Step 2: Append "bytes" into "dataBits" in appropriate encoding.
BitArray dataBits = new BitArray();
appendBytes(content, mode, dataBits, encoding);
// Step 3: Initialize QR code that can contain "dataBits".
int numInputBytes = dataBits.getSizeInBytes();
initQRCode(numInputBytes, ecLevel, mode, qrCode);
// Step 4: Build another bit vector that contains header and data.
BitArray headerAndDataBits = new BitArray();
// Step 4.5: Append ECI message if applicable
if (mode == Mode.BYTE && !DEFAULT_BYTE_MODE_ENCODING.equals(encoding)) {
CharacterSetECI eci = CharacterSetECI.getCharacterSetECIByName(encoding);
if (eci != null) {
appendECI(eci, headerAndDataBits);
}
}
appendModeInfo(mode, headerAndDataBits);
int numLetters = mode.equals(Mode.BYTE) ? dataBits.getSizeInBytes() : content.length();
appendLengthInfo(numLetters, qrCode.getVersion(), mode, headerAndDataBits);
headerAndDataBits.appendBitArray(dataBits);
// Step 5: Terminate the bits properly.
terminateBits(qrCode.getNumDataBytes(), headerAndDataBits);
// Step 6: Interleave data bits with error correction code.
BitArray finalBits = new BitArray();
interleaveWithECBytes(headerAndDataBits, qrCode.getNumTotalBytes(), qrCode.getNumDataBytes(),
qrCode.getNumRSBlocks(), finalBits);
// Step 7: Choose the mask pattern and set to "qrCode".
ByteMatrix matrix = new ByteMatrix(qrCode.getMatrixWidth(), qrCode.getMatrixWidth());
qrCode.setMaskPattern(chooseMaskPattern(finalBits, qrCode.getECLevel(), qrCode.getVersion(),
matrix));
// Step 8. Build the matrix and set it to "qrCode".
MatrixUtil.buildMatrix(finalBits, qrCode.getECLevel(), qrCode.getVersion(),
qrCode.getMaskPattern(), matrix);
qrCode.setMatrix(matrix);
// Step 9. Make sure we have a valid QR Code.
if (!qrCode.isValid()) {
throw new WriterException("Invalid QR code: " + qrCode.toString());
}
}
示例5: encode
import com.google.zxing.common.CharacterSetECI; //导入方法依赖的package包/类
public static void encode(String content, ErrorCorrectionLevel ecLevel, Map<EncodeHintType, ?> hints, QRCode qrCode) throws WriterException {
String encoding = hints == null ? null : (String) hints.get(EncodeHintType.CHARACTER_SET);
if (encoding == null) {
encoding = DEFAULT_BYTE_MODE_ENCODING;
}
// Step 1: Choose the mode (encoding).
Mode mode = chooseMode(content, encoding);
// Step 2: Append "bytes" into "dataBits" in appropriate encoding.
BitArray dataBits = new BitArray();
appendBytes(content, mode, dataBits, encoding);
// Step 3: Initialize QR code that can contain "dataBits".
int numInputBits = dataBits.getSize();
initQRCode(numInputBits, ecLevel, mode, qrCode);
// Step 4: Build another bit vector that contains header and data.
BitArray headerAndDataBits = new BitArray();
// Step 4.5: Append ECI message if applicable
if (mode == Mode.BYTE && !DEFAULT_BYTE_MODE_ENCODING.equals(encoding)) {
CharacterSetECI eci = CharacterSetECI.getCharacterSetECIByName(encoding);
if (eci != null) {
appendECI(eci, headerAndDataBits);
}
}
appendModeInfo(mode, headerAndDataBits);
int numLetters = mode == Mode.BYTE ? dataBits.getSizeInBytes() : content.length();
appendLengthInfo(numLetters, qrCode.getVersion(), mode, headerAndDataBits);
headerAndDataBits.appendBitArray(dataBits);
// Step 5: Terminate the bits properly.
terminateBits(qrCode.getNumDataBytes(), headerAndDataBits);
// Step 6: Interleave data bits with error correction code.
BitArray finalBits = new BitArray();
interleaveWithECBytes(headerAndDataBits, qrCode.getNumTotalBytes(), qrCode.getNumDataBytes(), qrCode.getNumRSBlocks(), finalBits);
// Step 7: Choose the mask pattern and set to "qrCode".
ByteMatrix matrix = new ByteMatrix(qrCode.getMatrixWidth(), qrCode.getMatrixWidth());
qrCode.setMaskPattern(chooseMaskPattern(finalBits, ecLevel, qrCode.getVersion(), matrix));
// Step 8. Build the matrix and set it to "qrCode".
MatrixUtil.buildMatrix(finalBits, ecLevel, qrCode.getVersion(), qrCode.getMaskPattern(), matrix);
qrCode.setMatrix(matrix);
// Step 9. Make sure we have a valid QR Code.
if (!qrCode.isValid()) {
throw new WriterException("Invalid QR code: " + qrCode.toString());
}
}