本文整理汇总了Java中com.google.zxing.qrcode.encoder.Encoder类的典型用法代码示例。如果您正苦于以下问题:Java Encoder类的具体用法?Java Encoder怎么用?Java Encoder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Encoder类属于com.google.zxing.qrcode.encoder包,在下文中一共展示了Encoder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: encode
import com.google.zxing.qrcode.encoder.Encoder; //导入依赖的package包/类
public BitMatrix encode(String contents, BarcodeFormat format, int width, int height, Map<EncodeHintType, ?> hints) throws WriterException {
if (contents.length() == 0) {
throw new IllegalArgumentException("Found empty contents");
} else if (format != BarcodeFormat.QR_CODE) {
throw new IllegalArgumentException("Can only encode QR_CODE, but got " + format);
} else if (width < 0 || height < 0) {
throw new IllegalArgumentException("Requested dimensions are too small: " + width + 'x' + height);
} else {
ErrorCorrectionLevel errorCorrectionLevel = ErrorCorrectionLevel.L;
int quietZone = 4;
if (hints != null) {
ErrorCorrectionLevel requestedECLevel = (ErrorCorrectionLevel) hints.get(EncodeHintType.ERROR_CORRECTION);
if (requestedECLevel != null) {
errorCorrectionLevel = requestedECLevel;
}
Integer quietZoneInt = (Integer) hints.get(EncodeHintType.MARGIN);
if (quietZoneInt != null) {
quietZone = quietZoneInt.intValue();
}
}
return renderResult(Encoder.encode(contents, errorCorrectionLevel, hints), width, height, quietZone);
}
}
示例2: toSingleQrCodeBufferedImage
import com.google.zxing.qrcode.encoder.Encoder; //导入依赖的package包/类
public static BufferedImage toSingleQrCodeBufferedImage(String s, ErrorCorrectionLevel ec, int scaleFactor) throws WriterException
{
QRCode qrCode = new QRCode();
Encoder.encode(s, ec, qrCode);
BufferedImage bufferedImage=MatrixToImageWriter.toBufferedImage(qrCode.getMatrix());
if (scaleFactor!=1)
{
int newWidth=bufferedImage.getWidth()*scaleFactor;
int newHeight=bufferedImage.getHeight()*scaleFactor;
Image image=bufferedImage.getScaledInstance(newWidth, newHeight, Image.SCALE_FAST);
bufferedImage=ImageIoUtils.toBufferedImage(image);
}
return(bufferedImage);
}
示例3: createQRCode
import com.google.zxing.qrcode.encoder.Encoder; //导入依赖的package包/类
/**
* Generate a QR code with the payment information of a given size, optionally, with branded
* @param paymentString A SPAYD string with payment information
* @return An image with the payment QR code
* @throws SpaydQRException
*/
public BufferedImage createQRCode(String paymentString) {
notEmpty(paymentString);
final BitMatrix matrix;
final int barsize;
final Writer writer = new MultiFormatWriter();
try {
final Map<EncodeHintType, Object> hints = new EnumMap<EncodeHintType, Object>(EncodeHintType.class);
hints.put(EncodeHintType.CHARACTER_SET, "ISO-8859-1");
final QRCode code = Encoder.encode(paymentString, ErrorCorrectionLevel.M, hints);
hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.M);
barsize = size / (code.getMatrix().getWidth() + 8);
matrix = writer.encode(paymentString, BarcodeFormat.QR_CODE, size, size, hints);
} catch (WriterException e) {
throw new SpaydQRException("Unable to create QR code", e);
}
final BufferedImage image = MatrixToImageWriter.toBufferedImage(matrix);
return isBranded() ? brandImage(image, barsize) : image;
}
示例4: getProtoQRCode
import com.google.zxing.qrcode.encoder.Encoder; //导入依赖的package包/类
/**
* @param contents Contents to encode.
* @param errorCorrectionLevel ErrorCorrectionLevel
* @return QR code object.
* @throws WriterException Refer to the messages below.
*/
private static QRCode getProtoQRCode(String contents, ErrorCorrectionLevel errorCorrectionLevel) throws WriterException {
if (contents.isEmpty()) {
throw new IllegalArgumentException("Found empty contents");
}
Hashtable<EncodeHintType, Object> hintMap = new Hashtable<>();
hintMap.put(EncodeHintType.CHARACTER_SET, "UTF-8");
hintMap.put(EncodeHintType.ERROR_CORRECTION, errorCorrectionLevel);
return Encoder.encode(contents, errorCorrectionLevel, hintMap);
}
示例5: encode
import com.google.zxing.qrcode.encoder.Encoder; //导入依赖的package包/类
@Override
public BitMatrix encode(String contents,
BarcodeFormat format,
int width,
int height,
Map<EncodeHintType,?> hints) throws WriterException {
if (contents.isEmpty()) {
throw new IllegalArgumentException("Found empty contents");
}
if (format != BarcodeFormat.QR_CODE) {
throw new IllegalArgumentException("Can only encode QR_CODE, but got " + format);
}
if (width < 0 || height < 0) {
throw new IllegalArgumentException("Requested dimensions are too small: " + width + 'x' +
height);
}
ErrorCorrectionLevel errorCorrectionLevel = ErrorCorrectionLevel.L;
int quietZone = QUIET_ZONE_SIZE;
if (hints != null) {
if (hints.containsKey(EncodeHintType.ERROR_CORRECTION)) {
errorCorrectionLevel = ErrorCorrectionLevel.valueOf(hints.get(EncodeHintType.ERROR_CORRECTION).toString());
}
if (hints.containsKey(EncodeHintType.MARGIN)) {
quietZone = Integer.parseInt(hints.get(EncodeHintType.MARGIN).toString());
}
}
QRCode code = Encoder.encode(contents, errorCorrectionLevel, hints);
return renderResult(code, width, height, quietZone);
}
示例6: encode
import com.google.zxing.qrcode.encoder.Encoder; //导入依赖的package包/类
public BitMatrix encode(String contents, BarcodeFormat format, int width, int height,
Map<EncodeHintType, ?> hints) throws WriterException {
if (contents.isEmpty()) {
throw new IllegalArgumentException("Found empty contents");
} else if (format != BarcodeFormat.QR_CODE) {
throw new IllegalArgumentException("Can only encode QR_CODE, but got " + format);
} else if (width < 0 || height < 0) {
throw new IllegalArgumentException("Requested dimensions are too small: " + width +
'x' + height);
} else {
ErrorCorrectionLevel errorCorrectionLevel = ErrorCorrectionLevel.L;
int quietZone = 4;
if (hints != null) {
ErrorCorrectionLevel requestedECLevel = (ErrorCorrectionLevel) hints.get
(EncodeHintType.ERROR_CORRECTION);
if (requestedECLevel != null) {
errorCorrectionLevel = requestedECLevel;
}
Integer quietZoneInt = (Integer) hints.get(EncodeHintType.MARGIN);
if (quietZoneInt != null) {
quietZone = quietZoneInt.intValue();
}
}
return renderResult(Encoder.encode(contents, errorCorrectionLevel, hints), width,
height, quietZone);
}
}
示例7: main
import com.google.zxing.qrcode.encoder.Encoder; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
final BufferedImage background = ImageIO.read(Main.class.getResource("nyan_sakamoto.png"));
Map<EncodeHintType, Object> hints = new HashMap<>();
hints.put(EncodeHintType.QR_VERSION, 5);
QRCode qrCode = Encoder.encode("Hello world, UniqR!", ErrorCorrectionLevel.H, hints);
UniqR<BufferedImage> uniqR = new UniqR<>(new JavaSEPlatform(), background, new QrCodeData(qrCode));
uniqR.setQrPatternColor(0xFF003366);
uniqR.setScale(3);
uniqR.setPadding(100);
showImage(uniqR.build().produceResult(), "Image");
}
示例8: encode
import com.google.zxing.qrcode.encoder.Encoder; //导入依赖的package包/类
@Override
public BitMatrix encode(String contents,
BarcodeFormat format,
int width,
int height,
Map<EncodeHintType,?> hints) throws WriterException {
if (contents.isEmpty()) {
throw new IllegalArgumentException("Found empty contents");
}
if (format != BarcodeFormat.QR_CODE) {
throw new IllegalArgumentException("Can only encode QR_CODE, but got " + format);
}
if (width < 0 || height < 0) {
throw new IllegalArgumentException("Requested dimensions are too small: " + width + 'x' +
height);
}
ErrorCorrectionLevel errorCorrectionLevel = ErrorCorrectionLevel.L;
int quietZone = QUIET_ZONE_SIZE;
if (hints != null) {
ErrorCorrectionLevel requestedECLevel = (ErrorCorrectionLevel) hints.get(EncodeHintType.ERROR_CORRECTION);
if (requestedECLevel != null) {
errorCorrectionLevel = requestedECLevel;
}
Integer quietZoneInt = (Integer) hints.get(EncodeHintType.MARGIN);
if (quietZoneInt != null) {
quietZone = quietZoneInt;
}
}
QRCode code = Encoder.encode(contents, errorCorrectionLevel, hints);
return renderResult(code, width, height, quietZone);
}
示例9: encode
import com.google.zxing.qrcode.encoder.Encoder; //导入依赖的package包/类
@Override
public BitMatrix encode(String contents,
BarcodeFormat format,
int width,
int height,
Map<EncodeHintType,?> hints) throws WriterException {
if (contents.length() == 0) {
throw new IllegalArgumentException("Found empty contents");
}
if (format != BarcodeFormat.QR_CODE) {
throw new IllegalArgumentException("Can only encode QR_CODE, but got " + format);
}
if (width < 0 || height < 0) {
throw new IllegalArgumentException("Requested dimensions are too small: " + width + 'x' +
height);
}
ErrorCorrectionLevel errorCorrectionLevel = ErrorCorrectionLevel.L;
int quietZone = QUIET_ZONE_SIZE;
if (hints != null) {
ErrorCorrectionLevel requestedECLevel = (ErrorCorrectionLevel) hints.get(EncodeHintType.ERROR_CORRECTION);
if (requestedECLevel != null) {
errorCorrectionLevel = requestedECLevel;
}
Integer quietZoneInt = (Integer) hints.get(EncodeHintType.MARGIN);
if (quietZoneInt != null) {
quietZone = quietZoneInt;
}
}
QRCode code = Encoder.encode(contents, errorCorrectionLevel, hints);
return renderResult(code, width, height, quietZone);
}
示例10: encode
import com.google.zxing.qrcode.encoder.Encoder; //导入依赖的package包/类
@Override
public BitMatrix encode(String contents,
BarcodeFormat format,
int width,
int height,
Map<EncodeHintType, ?> hints) throws WriterException {
if (contents.isEmpty()) {
throw new IllegalArgumentException("Found empty contents");
}
if (format != BarcodeFormat.QR_CODE) {
throw new IllegalArgumentException("Can only encode QR_CODE, but got " + format);
}
if (width < 0 || height < 0) {
throw new IllegalArgumentException("Requested dimensions are too small: " + width + 'x' +
height);
}
ErrorCorrectionLevel errorCorrectionLevel = ErrorCorrectionLevel.L;
int quietZone = QUIET_ZONE_SIZE;
if (hints != null) {
ErrorCorrectionLevel requestedECLevel = (ErrorCorrectionLevel) hints.get(EncodeHintType.ERROR_CORRECTION);
if (requestedECLevel != null) {
errorCorrectionLevel = requestedECLevel;
}
Integer quietZoneInt = (Integer) hints.get(EncodeHintType.MARGIN);
if (quietZoneInt != null) {
quietZone = quietZoneInt;
}
}
QRCode code = Encoder.encode(contents, errorCorrectionLevel, hints);
return renderResult(code, width, height, quietZone);
}
示例11: encode
import com.google.zxing.qrcode.encoder.Encoder; //导入依赖的package包/类
@Override
public BitMatrix encode(String contents,
BarcodeFormat format,
int width,
int height,
Map<EncodeHintType, ?> hints) throws WriterException {
if (contents.length() == 0) {
throw new IllegalArgumentException("Found empty contents");
}
if (format != BarcodeFormat.QR_CODE) {
throw new IllegalArgumentException("Can only encode QR_CODE, but got " + format);
}
if (width < 0 || height < 0) {
throw new IllegalArgumentException("Requested dimensions are too small: " + width + 'x' +
height);
}
ErrorCorrectionLevel errorCorrectionLevel = ErrorCorrectionLevel.L;
int quietZone = QUIET_ZONE_SIZE;
if (hints != null) {
ErrorCorrectionLevel requestedECLevel = (ErrorCorrectionLevel) hints.get(EncodeHintType.ERROR_CORRECTION);
if (requestedECLevel != null) {
errorCorrectionLevel = requestedECLevel;
}
Integer quietZoneInt = (Integer) hints.get(EncodeHintType.MARGIN);
if (quietZoneInt != null) {
quietZone = quietZoneInt;
}
}
QRCode code = Encoder.encode(contents, errorCorrectionLevel, hints);
return renderResult(code, width, height, quietZone);
}
示例12: toBitmap
import com.google.zxing.qrcode.encoder.Encoder; //导入依赖的package包/类
public static Bitmap toBitmap(String data) {
try {
return toBitmap(Encoder.encode(data, ErrorCorrectionLevel.M) , Color.BLACK, Color.TRANSPARENT);
} catch (WriterException e) {
e.printStackTrace();
}
return null;
}
示例13: encode
import com.google.zxing.qrcode.encoder.Encoder; //导入依赖的package包/类
/**
* This object renders a QR Code as a ByteMatrix 2D array of greyscale
* values.
*
* @author [email protected] (Daniel Switkin)
*/
public ByteMatrix encode(String contents) throws WriterException {
if (contents == null || contents.length() == 0) {
throw new IllegalArgumentException("Found empty contents");
}
Encoder.encode(contents, ErrorCorrectionLevel.L);
return renderResult(code, QR_CODE_ELEMENT_MULTIPLE);
}
示例14: encode
import com.google.zxing.qrcode.encoder.Encoder; //导入依赖的package包/类
@Override
public BitMatrix encode(String contents, BarcodeFormat format, int width, int height, Map<EncodeHintType, ?> hints)
throws WriterException {
if (contents.isEmpty()) {
throw new IllegalArgumentException("Found empty contents");
}
if (format != BarcodeFormat.QR_CODE) {
throw new IllegalArgumentException("Can only encode QR_CODE, but got " + format);
}
if (width < 0 || height < 0) {
throw new IllegalArgumentException("Requested dimensions are too small: " + width + 'x' + height);
}
ErrorCorrectionLevel errorCorrectionLevel = ErrorCorrectionLevel.L;
int quietZone = QUIET_ZONE_SIZE;
if (hints != null) {
ErrorCorrectionLevel requestedECLevel = (ErrorCorrectionLevel) hints.get(EncodeHintType.ERROR_CORRECTION);
if (requestedECLevel != null) {
errorCorrectionLevel = requestedECLevel;
}
Integer quietZoneInt = (Integer) hints.get(EncodeHintType.MARGIN);
if (quietZoneInt != null) {
quietZone = quietZoneInt;
}
}
QRCode code = Encoder.encode(contents, errorCorrectionLevel, hints);
return renderResult(code, width, height, quietZone);
}
示例15: encode
import com.google.zxing.qrcode.encoder.Encoder; //导入依赖的package包/类
public BitMatrix encode(String contents, BarcodeFormat format, int width, int height,
Hashtable hints) throws WriterException {
if (contents == null || contents.length() == 0) {
throw new IllegalArgumentException("Found empty contents");
}
if (format != BarcodeFormat.QR_CODE) {
throw new IllegalArgumentException("Can only encode QR_CODE, but got " + format);
}
if (width < 0 || height < 0) {
throw new IllegalArgumentException("Requested dimensions are too small: " + width + 'x' +
height);
}
ErrorCorrectionLevel errorCorrectionLevel = ErrorCorrectionLevel.L;
if (hints != null) {
ErrorCorrectionLevel requestedECLevel = (ErrorCorrectionLevel) hints.get(EncodeHintType.ERROR_CORRECTION);
if (requestedECLevel != null) {
errorCorrectionLevel = requestedECLevel;
}
}
QRCode code = new QRCode();
Encoder.encode(contents, errorCorrectionLevel, hints, code);
return renderResult(code, width, height);
}