当前位置: 首页>>代码示例>>Java>>正文


Java Encoder类代码示例

本文整理汇总了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);
    }
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:24,代码来源:QRCodeWriter.java

示例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);
}
 
开发者ID:williamgrosset,项目名称:OSCAR-ConCert,代码行数:18,代码来源:QrCodeUtils.java

示例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;
}
 
开发者ID:martiner,项目名称:spayd,代码行数:28,代码来源:SpaydQRFactory.java

示例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);
}
 
开发者ID:SumiMakito,项目名称:AwesomeQRCode,代码行数:16,代码来源:AwesomeQRCode.java

示例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);
}
 
开发者ID:amap-demo,项目名称:weex-3d-map,代码行数:35,代码来源:QRCodeWriter.java

示例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);
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:28,代码来源:QRCodeWriter.java

示例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");
}
 
开发者ID:mariotaku,项目名称:UniqR,代码行数:13,代码来源:Main.java

示例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);
}
 
开发者ID:SudarAbisheck,项目名称:ZXing-Orient,代码行数:37,代码来源:QRCodeWriter.java

示例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);
}
 
开发者ID:atomsheep,项目名称:sres-app,代码行数:37,代码来源:QRCodeWriter.java

示例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);
}
 
开发者ID:Ag47,项目名称:TrueTone,代码行数:37,代码来源:QRCodeWriter.java

示例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);
}
 
开发者ID:yakovenkodenis,项目名称:Discounty,代码行数:37,代码来源:QRCodeWriter.java

示例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;
}
 
开发者ID:RCasatta,项目名称:EternityWallAndroid,代码行数:9,代码来源:QrBitmap.java

示例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);
}
 
开发者ID:cping,项目名称:RipplePower,代码行数:16,代码来源:SendCodeGenerator.java

示例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);
}
 
开发者ID:cping,项目名称:RipplePower,代码行数:33,代码来源:QRCodeWriter.java

示例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);
}
 
开发者ID:emdete,项目名称:Simplicissimus,代码行数:29,代码来源:QRCodeWriter.java


注:本文中的com.google.zxing.qrcode.encoder.Encoder类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。