类com.google.zxing.WriterException源码实例Demo

下面列出了怎么用com.google.zxing.WriterException的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: mollyim-android   文件: QrCode.java
public static @NonNull Bitmap create(String data) {
  try {
    BitMatrix result = new QRCodeWriter().encode(data, BarcodeFormat.QR_CODE, 512, 512);
    Bitmap    bitmap = Bitmap.createBitmap(result.getWidth(), result.getHeight(), Bitmap.Config.ARGB_8888);

    for (int y = 0; y < result.getHeight(); y++) {
      for (int x = 0; x < result.getWidth(); x++) {
        if (result.get(x, y)) {
          bitmap.setPixel(x, y, Color.BLACK);
        }
      }
    }

    return bitmap;
  } catch (WriterException e) {
    Log.w(TAG, e);
    return Bitmap.createBitmap(512, 512, Bitmap.Config.ARGB_8888);
  }
}
 
源代码2 项目: Tok-Android   文件: QRCodeEncode.java
public Bitmap encodeAsBitmap() throws WriterException {
    if (!encoded) return null;

    Map<EncodeHintType, Object> hints = null;
    String encoding = guessAppropriateEncoding(contents);
    if (encoding != null) {
        hints = new EnumMap<EncodeHintType, Object>(EncodeHintType.class);
        hints.put(EncodeHintType.CHARACTER_SET, encoding);
    }
    MultiFormatWriter writer = new MultiFormatWriter();
    BitMatrix result = writer.encode(contents, format, dimension, dimension, hints);
    int width = result.getWidth();
    int height = result.getHeight();
    int[] pixels = new int[width * height];
    // All are 0, or black, by default
    for (int y = 0; y < height; y++) {
        int offset = y * width;
        for (int x = 0; x < width; x++) {
            pixels[offset + x] = result.get(x, y) ? BLACK : WHITE;
        }
    }

    Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    bitmap.setPixels(pixels, 0, width, 0, 0, width, height);
    return bitmap;
}
 
源代码3 项目: QrCodeLib   文件: EncodingHandler.java
public static Bitmap createQRCode(String str, int widthAndHeight) throws WriterException {
    Hashtable<EncodeHintType, String> hints = new Hashtable<EncodeHintType, String>();
    hints.put(EncodeHintType.CHARACTER_SET, "utf-8");
    BitMatrix matrix = new MultiFormatWriter().encode(str,
            BarcodeFormat.QR_CODE, widthAndHeight, widthAndHeight);
    int width = matrix.getWidth();
    int height = matrix.getHeight();
    int[] pixels = new int[width * height];

    for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
            if (matrix.get(x, y)) {
                pixels[y * width + x] = BLACK;
            }
        }
    }
    Bitmap bitmap = Bitmap.createBitmap(width, height,
            Bitmap.Config.ARGB_8888);
    bitmap.setPixels(pixels, 0, width, 0, 0, width, height);
    return bitmap;
}
 
源代码4 项目: QrCodeLib   文件: QrCodeGenerator.java
public static Bitmap getQrCodeImage(String data, int width, int height) {
    if (data == null || data.length() == 0) {
        return null;
    }
    Map<EncodeHintType, Object> hintsMap = new HashMap<>(3);
    hintsMap.put(EncodeHintType.CHARACTER_SET, "utf-8");
    hintsMap.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
    hintsMap.put(EncodeHintType.MARGIN, 0);
    try {
        BitMatrix bitMatrix = new MultiFormatWriter().encode(data, BarcodeFormat.QR_CODE, width, height, hintsMap);
        Bitmap bitmap = bitMatrix2Bitmap(bitMatrix);
        return bitmap;
    } catch (WriterException e) {
        e.printStackTrace();
    }
    return null;
}
 
源代码5 项目: vmqApk   文件: EncodingHandler.java
public static Bitmap createQRCode(String str, int widthAndHeight) throws WriterException {
	Hashtable<EncodeHintType, String> hints = new Hashtable<EncodeHintType, String>();
       hints.put(EncodeHintType.CHARACTER_SET, "utf-8"); 
	BitMatrix matrix = new MultiFormatWriter().encode(str,
			BarcodeFormat.QR_CODE, widthAndHeight, widthAndHeight);
	int width = matrix.getWidth();
	int height = matrix.getHeight();
	int[] pixels = new int[width * height];
	
	for (int y = 0; y < height; y++) {
		for (int x = 0; x < width; x++) {
			if (matrix.get(x, y)) {
				pixels[y * width + x] = BLACK;
			}
		}
	}
	Bitmap bitmap = Bitmap.createBitmap(width, height,
			Bitmap.Config.ARGB_8888);
	bitmap.setPixels(pixels, 0, width, 0, 0, width, height);
	return bitmap;
}
 
源代码6 项目: SlidesRemote   文件: QRCodeEngine.java
public static Image encode(String data, int width, int height) {
    try {
        BitMatrix byteMatrix = new QRCodeWriter().encode(data, BarcodeFormat.QR_CODE, width, height);
        BufferedImage bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
        bufferedImage.createGraphics();
        Graphics2D graphics = (Graphics2D) bufferedImage.getGraphics();
        graphics.setColor(Color.decode("#00adb5"));
        graphics.fillRect(0, 0, width, height);
        graphics.setColor(Color.BLACK);
        for (int i = 0; i < height; i++) {
            for (int j = 0; j < width; j++) {
                if (byteMatrix.get(i, j)) {
                    graphics.fillRect(i, j, 1, 1);
                }
            }
        }

        return SwingFXUtils.toFXImage(bufferedImage, null);
    } catch (WriterException ex) {
        ex.printStackTrace();
        return null;
    }
}
 
源代码7 项目: Auditor   文件: AttestationActivity.java
private Bitmap createQrCode(final byte[] contents) {
    final BitMatrix result;
    try {
        final QRCodeWriter writer = new QRCodeWriter();
        final Map<EncodeHintType,Object> hints = new EnumMap<>(EncodeHintType.class);
        hints.put(EncodeHintType.CHARACTER_SET, StandardCharsets.ISO_8859_1);
        final int size = Math.min(imageView.getWidth(), imageView.getHeight());
        result = writer.encode(new String(contents, StandardCharsets.ISO_8859_1), BarcodeFormat.QR_CODE,
                size, size, hints);
    } catch (WriterException e) {
        throw new RuntimeException(e);
    }

    final int width = result.getWidth();
    final int height = result.getHeight();
    final int[] pixels = new int[width * height];
    for (int y = 0; y < height; y++) {
        final int offset = y * width;
        for (int x = 0; x < width; x++) {
            pixels[offset + x] = result.get(x, y) ? BLACK : WHITE;
        }
    }

    return Bitmap.createBitmap(pixels, width, height, Bitmap.Config.RGB_565);
}
 
源代码8 项目: Quelea   文件: MobileServerPreference.java
private Image getQRImage() {
    if (qrImage == null) {
        QRCodeWriter qrCodeWriter = new QRCodeWriter();
        int qrWidth = 500;
        int qrHeight = 500;
        BitMatrix byteMatrix = null;
        try {
            byteMatrix = qrCodeWriter.encode(getMLURL(), BarcodeFormat.QR_CODE, qrWidth, qrHeight);
        } catch (WriterException ex) {
            LOGGER.log(Level.WARNING, "Error writing QR code", ex);
        }
        qrImage = MatrixToImageWriter.toBufferedImage(byteMatrix);
    }
    WritableImage fxImg = new WritableImage(500, 500);
    SwingFXUtils.toFXImage(qrImage, fxImg);
    return fxImg;
}
 
源代码9 项目: guarda-android-wallets   文件: QrCodeUtils.java
public static Bitmap textToBarCode(String data) {
    MultiFormatWriter writer = new MultiFormatWriter();


    String finaldata = Uri.encode(data, "utf-8");

    BitMatrix bm = null;
    try {
        bm = writer.encode(finaldata, BarcodeFormat.CODE_128, 150, 150);
    } catch (WriterException e) {
        e.printStackTrace();
    }
    Bitmap bitmap = Bitmap.createBitmap(180, 40, Bitmap.Config.ARGB_8888);

    for (int i = 0; i < 180; i++) {//width
        for (int j = 0; j < 40; j++) {//height
            bitmap.setPixel(i, j, bm.get(i, j) ? BLACK : WHITE);
        }
    }

    return bitmap;
}
 
源代码10 项目: java-study   文件: QrCodeCreateUtil.java
/**
 * 生成包含字符串信息的二维码图片
 *
 * @param outputStream 文件输出流路径
 * @param content      二维码携带信息
 * @param qrCodeSize   二维码图片大小
 * @param imageFormat  二维码的格式
 * @throws WriterException
 * @throws IOException
 */
public static boolean createQrCode(OutputStream outputStream, String content, int qrCodeSize, String imageFormat) throws WriterException, IOException {
    //设置二维码纠错级别MAP
    Hashtable<EncodeHintType, ErrorCorrectionLevel> hintMap = new Hashtable<EncodeHintType, ErrorCorrectionLevel>();
    hintMap.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.L);  // 矫错级别
    QRCodeWriter qrCodeWriter = new QRCodeWriter();
    //创建比特矩阵(位矩阵)的QR码编码的字符串
    BitMatrix byteMatrix = qrCodeWriter.encode(content, BarcodeFormat.QR_CODE, qrCodeSize, qrCodeSize, hintMap);
    // 使BufferedImage勾画QRCode  (matrixWidth 是行二维码像素点)
    int matrixWidth = byteMatrix.getWidth();
    BufferedImage image = new BufferedImage(matrixWidth - 200, matrixWidth - 200, BufferedImage.TYPE_INT_RGB);
    image.createGraphics();
    Graphics2D graphics = (Graphics2D) image.getGraphics();
    graphics.setColor(Color.WHITE);
    graphics.fillRect(0, 0, matrixWidth, matrixWidth);
    // 使用比特矩阵画并保存图像
    graphics.setColor(Color.BLACK);
    for (int i = 0; i < matrixWidth; i++) {
        for (int j = 0; j < matrixWidth; j++) {
            if (byteMatrix.get(i, j)) {
                graphics.fillRect(i - 100, j - 100, 1, 1);
            }
        }
    }
    return ImageIO.write(image, imageFormat, outputStream);
}
 
源代码11 项目: QrCodeDemo4   文件: EncodingHandler.java
public static Bitmap createQRCode(String str, int widthAndHeight) throws WriterException {
	Hashtable<EncodeHintType, String> hints = new Hashtable<EncodeHintType, String>();
       hints.put(EncodeHintType.CHARACTER_SET, "utf-8"); 
	BitMatrix matrix = new MultiFormatWriter().encode(str,
			BarcodeFormat.QR_CODE, widthAndHeight, widthAndHeight);
	int width = matrix.getWidth();
	int height = matrix.getHeight();
	int[] pixels = new int[width * height];
	
	for (int y = 0; y < height; y++) {
		for (int x = 0; x < width; x++) {
			if (matrix.get(x, y)) {
				pixels[y * width + x] = BLACK;
			}
		}
	}
	Bitmap bitmap = Bitmap.createBitmap(width, height,
			Bitmap.Config.ARGB_8888);
	bitmap.setPixels(pixels, 0, width, 0, 0, width, height);
	return bitmap;
}
 
源代码12 项目: springboot-pay-example   文件: PayUtil.java
/**
 * 根据url生成二位图片对象
 *
 * @param codeUrl
 * @return
 * @throws WriterException
 */
public static BufferedImage getQRCodeImge(String codeUrl) throws WriterException {
    Map<EncodeHintType, Object> hints = new Hashtable();
    hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.M);
    hints.put(EncodeHintType.CHARACTER_SET, "UTF8");
    int width = 256;
    BitMatrix bitMatrix = (new MultiFormatWriter()).encode(codeUrl, BarcodeFormat.QR_CODE, width, width, hints);
    BufferedImage image = new BufferedImage(width, width, 1);
    for(int x = 0; x < width; ++x) {
        for(int y = 0; y < width; ++y) {
            image.setRGB(x, y, bitMatrix.get(x, y) ? -16777216 : -1);
        }
    }

    return image;
}
 
源代码13 项目: trigger   文件: QRShowActivity.java
private void generateQR(Setup setup) throws Exception {
    MultiFormatWriter multiFormatWriter = new MultiFormatWriter();
    int data_length = 0;
    try {
        JSONObject obj = Settings.toJsonObject(setup);
        String data = encodeSetup(obj);
        data_length = data.length();

        // data has to be a string
        BitMatrix bitMatrix = multiFormatWriter.encode(data, BarcodeFormat.QR_CODE, 1080, 1080);
        BarcodeEncoder barcodeEncoder = new BarcodeEncoder();
        Bitmap bitmap = barcodeEncoder.createBitmap(bitMatrix);
        ((ImageView) findViewById(R.id.QRView)).setImageBitmap(bitmap);
    } catch (WriterException e) {
        Toast.makeText(this, e.getMessage() + " (" + data_length + " Bytes)", Toast.LENGTH_LONG).show();
        finish();
    }
}
 
源代码14 项目: ScreenCapture   文件: Encoder.java
static void appendAlphanumericBytes(CharSequence content, BitArray bits) throws WriterException {
  int length = content.length();
  int i = 0;
  while (i < length) {
    int code1 = getAlphanumericCode(content.charAt(i));
    if (code1 == -1) {
      throw new WriterException();
    }
    if (i + 1 < length) {
      int code2 = getAlphanumericCode(content.charAt(i + 1));
      if (code2 == -1) {
        throw new WriterException();
      }
      // Encode two alphanumeric letters in 11 bits.
      bits.appendBits(code1 * 45 + code2, 11);
      i += 2;
    } else {
      // Encode one alphanumeric letter in six bits.
      bits.appendBits(code1, 6);
      i++;
    }
  }
}
 
源代码15 项目: ScreenCapture   文件: Encoder.java
static void appendKanjiBytes(String content, BitArray bits) throws WriterException {
  byte[] bytes;
  try {
    bytes = content.getBytes("Shift_JIS");
  } catch (UnsupportedEncodingException uee) {
    throw new WriterException(uee);
  }
  int length = bytes.length;
  for (int i = 0; i < length; i += 2) {
    int byte1 = bytes[i] & 0xFF;
    int byte2 = bytes[i + 1] & 0xFF;
    int code = (byte1 << 8) | byte2;
    int subtracted = -1;
    if (code >= 0x8140 && code <= 0x9ffc) {
      subtracted = code - 0x8140;
    } else if (code >= 0xe040 && code <= 0xebbf) {
      subtracted = code - 0xc140;
    }
    if (subtracted == -1) {
      throw new WriterException("Invalid byte sequence");
    }
    int encoded = ((subtracted >> 8) * 0xc0) + (subtracted & 0xff);
    bits.appendBits(encoded, 13);
  }
}
 
源代码16 项目: ScreenCapture   文件: MatrixUtil.java
static void maybeEmbedVersionInfo(Version version, ByteMatrix matrix) throws WriterException {
  if (version.getVersionNumber() < 7) {  // Version info is necessary if version >= 7.
    return;  // Don't need version info.
  }
  BitArray versionInfoBits = new BitArray();
  makeVersionInfoBits(version, versionInfoBits);

  int bitIndex = 6 * 3 - 1;  // It will decrease from 17 to 0.
  for (int i = 0; i < 6; ++i) {
    for (int j = 0; j < 3; ++j) {
      // Place bits in LSB (least significant bit) to MSB order.
      boolean bit = versionInfoBits.get(bitIndex);
      bitIndex--;
      // Left bottom corner.
      matrix.set(i, matrix.getHeight() - 11 + j, bit);
      // Right bottom corner.
      matrix.set(matrix.getHeight() - 11 + j, i, bit);
    }
  }
}
 
源代码17 项目: ScreenCapture   文件: MatrixUtil.java
static void makeTypeInfoBits(ErrorCorrectionLevel ecLevel, int maskPattern, BitArray bits)
    throws WriterException {
  if (!QRCode.isValidMaskPattern(maskPattern)) {
    throw new WriterException("Invalid mask pattern");
  }
  int typeInfo = (ecLevel.getBits() << 3) | maskPattern;
  bits.appendBits(typeInfo, 5);

  int bchCode = calculateBCHCode(typeInfo, TYPE_INFO_POLY);
  bits.appendBits(bchCode, 10);

  BitArray maskBits = new BitArray();
  maskBits.appendBits(TYPE_INFO_MASK_PATTERN, 15);
  bits.xor(maskBits);

  if (bits.getSize() != 15) {  // Just in case.
    throw new WriterException("should not happen but we got: " + bits.getSize());
  }
}
 
源代码18 项目: ScreenCapture   文件: OneDimensionalCodeWriter.java
/**
 * Encode the contents following specified format.
 * {@code width} and {@code height} are required size. This method may return bigger size
 * {@code BitMatrix} when specified size is too small. The user can set both {@code width} and
 * {@code height} to zero to get minimum size barcode. If negative value is set to {@code width}
 * or {@code height}, {@code IllegalArgumentException} is thrown.
 */
@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 (width < 0 || height < 0) {
    throw new IllegalArgumentException("Negative size is not allowed. Input: "
                                           + width + 'x' + height);
  }

  int sidesMargin = getDefaultMargin();
  if (hints != null && hints.containsKey(EncodeHintType.MARGIN)) {
    sidesMargin = Integer.parseInt(hints.get(EncodeHintType.MARGIN).toString());
  }

  boolean[] code = encode(contents);
  return renderResult(code, width, height, sidesMargin);
}
 
源代码19 项目: Tok-Android   文件: SharePresenter.java
private void generateQR() {
    mQrPath = StorageUtil.getShareQrCodeFile();
    String qrContent = StringUtils.formatTxFromResId(R.string.share_qr_content, mSelfAddress);
    LogUtil.i(TAG, "share qr content:" + qrContent);
    int qrCodeSize = 800;
    QRCodeEncode qrCodeEncoder =
        new QRCodeEncode(qrContent, null, Contents.Type.TEXT, BarcodeFormat.QR_CODE.toString(),
            qrCodeSize);
    try {
        ImageUtils.compressBitmap(qrCodeEncoder.encodeAsBitmap(), mQrPath);
    } catch (WriterException e) {
        e.printStackTrace();
    }
    mShareView.showQr(mQrPath);
}
 
源代码20 项目: Tok-Android   文件: TokIdPresenter.java
private String generateQR(String tokId) {
    String outPath = StorageUtil.getQrCodeFile();
    int qrCodeSize = 800;
    QRCodeEncode qrCodeEncoder =
        new QRCodeEncode(tokId, null, Contents.Type.TEXT, BarcodeFormat.QR_CODE.toString(),
            qrCodeSize);
    try {
        ImageUtils.compressBitmap(qrCodeEncoder.encodeAsBitmap(), outPath);
    } catch (WriterException e) {
        e.printStackTrace();
    }
    return outPath;
}
 
源代码21 项目: QrCodeLib   文件: EncodingHandler.java
/**
 * 创建二维码
 *
 * @param content   content
 * @param widthPix  widthPix
 * @param heightPix heightPix
 * @param logoBm    logoBm
 * @return 二维码
 */
public static Bitmap createQRCode(String content, int widthPix, int heightPix, Bitmap logoBm) {
    try {
        if (content == null || "".equals(content)) {
            return null;
        }
        // 配置参数
        Map<EncodeHintType, Object> hints = new HashMap<>();
        hints.put(EncodeHintType.CHARACTER_SET, "utf-8");
        // 容错级别
        hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
        // 图像数据转换,使用了矩阵转换
        BitMatrix bitMatrix = new QRCodeWriter().encode(content, BarcodeFormat.QR_CODE, widthPix,
                heightPix, hints);
        int[] pixels = new int[widthPix * heightPix];
        // 下面这里按照二维码的算法,逐个生成二维码的图片,
        // 两个for循环是图片横列扫描的结果
        for (int y = 0; y < heightPix; y++) {
            for (int x = 0; x < widthPix; x++) {
                if (bitMatrix.get(x, y)) {
                    pixels[y * widthPix + x] = 0xff000000;
                } else {
                    pixels[y * widthPix + x] = 0xffffffff;
                }
            }
        }
        // 生成二维码图片的格式,使用ARGB_8888
        Bitmap bitmap = Bitmap.createBitmap(widthPix, heightPix, Bitmap.Config.ARGB_8888);
        bitmap.setPixels(pixels, 0, widthPix, 0, 0, widthPix, heightPix);
        if (logoBm != null) {
            bitmap = addLogo(bitmap, logoBm);
        }
        //必须使用compress方法将bitmap保存到文件中再进行读取。直接返回的bitmap是没有任何压缩的,内存消耗巨大!
        return bitmap;
    } catch (WriterException e) {
        e.printStackTrace();
    }
    return null;
}
 
源代码22 项目: vmqApk   文件: EncodingHandler.java
/**
 * 创建二维码
 *
 * @param content   content
 * @param widthPix  widthPix
 * @param heightPix heightPix
 * @param logoBm    logoBm
 * @return 二维码
 */
public static Bitmap createQRCode(String content, int widthPix, int heightPix, Bitmap logoBm) {
	try {
		if (content == null || "".equals(content)) {
			return null;
		}
		// 配置参数
		Map<EncodeHintType, Object> hints = new HashMap<>();
		hints.put(EncodeHintType.CHARACTER_SET, "utf-8");
		// 容错级别
		hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
		// 图像数据转换,使用了矩阵转换
		BitMatrix bitMatrix = new QRCodeWriter().encode(content, BarcodeFormat.QR_CODE, widthPix,
				heightPix, hints);
		int[] pixels = new int[widthPix * heightPix];
		// 下面这里按照二维码的算法,逐个生成二维码的图片,
		// 两个for循环是图片横列扫描的结果
		for (int y = 0; y < heightPix; y++) {
			for (int x = 0; x < widthPix; x++) {
				if (bitMatrix.get(x, y)) {
					pixels[y * widthPix + x] = 0xff000000;
				} else {
					pixels[y * widthPix + x] = 0xffffffff;
				}
			}
		}
		// 生成二维码图片的格式,使用ARGB_8888
		Bitmap bitmap = Bitmap.createBitmap(widthPix, heightPix, Bitmap.Config.ARGB_8888);
		bitmap.setPixels(pixels, 0, widthPix, 0, 0, widthPix, heightPix);
		if (logoBm != null) {
			bitmap = addLogo(bitmap, logoBm);
		}
		//必须使用compress方法将bitmap保存到文件中再进行读取。直接返回的bitmap是没有任何压缩的,内存消耗巨大!
		return bitmap;
	} catch (WriterException e) {
		e.printStackTrace();
	}
	return null;
}
 
源代码23 项目: java-totp   文件: ZxingPngQrGeneratorTest.java
@Test
public void testExceptionIsWrapped() throws WriterException {
    Throwable exception = new RuntimeException();
    Writer writer = mock(Writer.class);
    when(writer.encode(anyString(), any(), anyInt(), anyInt())).thenThrow(exception);

    ZxingPngQrGenerator generator = new ZxingPngQrGenerator(writer);

    QrGenerationException e = assertThrows(QrGenerationException.class, () -> {
        generator.generate(getData());
    });

    assertEquals("Failed to generate QR code. See nested exception.", e.getMessage());
    assertEquals(exception, e.getCause());
}
 
源代码24 项目: bcm-android   文件: QREncoder.java
public Bitmap encodeAsBitmap() throws WriterException {
    if (!encoded)
        return null;

    Map<EncodeHintType, Object> hints = null;
    String encoding = guessAppropriateEncoding(contents);
    if (encoding != null) {
        hints = new EnumMap<EncodeHintType, Object>(EncodeHintType.class);
        hints.put(EncodeHintType.CHARACTER_SET, encoding);
    }
    MultiFormatWriter writer = new MultiFormatWriter();
    BitMatrix result = writer.encode(contents, format, dimension, dimension, hints);
    int width = result.getWidth();
    int height = result.getHeight();
    int[] pixels = new int[width * height];
    // All are 0, or black, by default
    for (int y = 0; y < height; y++) {
        int offset = y * width;
        for (int x = 0; x < width; x++) {
            pixels[offset + x] = result.get(x, y) ? BLACK : WHITE;
        }
    }

    Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    bitmap.setPixels(pixels, 0, width, 0, 0, width, height);
    return bitmap;
}
 
源代码25 项目: bcm-android   文件: RequestEtherActivity.java
public void updateQR() {
    int qrCodeDimention = 400;
    String iban = "iban:" + selectedEtherAddress;
    if (amount.getText().toString().length() > 0 && new BigDecimal(amount.getText().toString()).compareTo(new BigDecimal("0")) > 0) {
        iban += "?amount=" + amount.getText().toString();
    }

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    QREncoder qrCodeEncoder;
    if (prefs.getBoolean("qr_encoding_erc", true)) {
        AddressEncoder temp = new AddressEncoder(selectedEtherAddress);
        if (amount.getText().toString().length() > 0 && new BigDecimal(amount.getText().toString()).compareTo(new BigDecimal("0")) > 0)
            temp.setAmount(amount.getText().toString());
        qrCodeEncoder = new QREncoder(AddressEncoder.encodeERC(temp), null,
                Contents.Type.TEXT, BarcodeFormat.QR_CODE.toString(), qrCodeDimention);
    } else {
        qrCodeEncoder = new QREncoder(iban, null,
                Contents.Type.TEXT, BarcodeFormat.QR_CODE.toString(), qrCodeDimention);
    }

    try {
        Bitmap bitmap = qrCodeEncoder.encodeAsBitmap();
        qr.setImageBitmap(bitmap);
    } catch (WriterException e) {
        e.printStackTrace();
    }
}
 
源代码26 项目: bcm-android   文件: PrivateKeyActivity.java
public void updateQR(String privateKey) {
    int qrCodeDimention = 400;
    QREncoder qrCodeEncoder = new QREncoder(privateKey, null, Contents.Type.TEXT, BarcodeFormat.QR_CODE.toString(), qrCodeDimention);

    try {
        Bitmap bitmap = qrCodeEncoder.encodeAsBitmap();
        qr.setImageBitmap(bitmap);
    } catch (WriterException e) {
        e.printStackTrace();
    }
}
 
源代码27 项目: zom-android-matrix   文件: QrGenAsyncTask.java
@SuppressWarnings("deprecation")
  @TargetApi(13)
  @Override
  protected Void doInBackground(String... s) {
      String qrData = s[0];
      /*
      //Display display = activity.getWindowManager().getDefaultDisplay();

      Point outSize = new Point();
      int x, y, qrCodeDimension;
      if (Build.VERSION.SDK_INT >= 13) {
          view.getSize(outSize);
          x = outSize.x;
          y = outSize.y;
      } else {
          x = display.getWidth();
          y = display.getHeight();
      }
      if (x < y)
          qrCodeDimension = x;
      else
          qrCodeDimension = y;
      **/

//      Log.i(TAG, "generating QRCode Bitmap of " + qrCodeDimension + "x" + qrCodeDimension);
      QRCodeEncoder qrCodeEncoder = new QRCodeEncoder(qrData, null,
              Contents.Type.TEXT, BarcodeFormat.QR_CODE.toString(), qrCodeDimension);

      try {
          qrBitmap = qrCodeEncoder.encodeAsBitmap();
      } catch (WriterException e) {
          Log.e(TAG, e.getMessage());
      }
      return null;
  }
 
源代码28 项目: zom-android-matrix   文件: QRCodeEncoder.java
public Bitmap encodeAsBitmap() throws WriterException {
    if (!encoded) return null;

    Map<EncodeHintType, Object> hints = null;
    String encoding = guessAppropriateEncoding(contents);
    if (encoding != null) {
        hints = new EnumMap<>(EncodeHintType.class);
        hints.put(EncodeHintType.CHARACTER_SET, encoding);
    }
    MultiFormatWriter writer = new MultiFormatWriter();
    BitMatrix result = writer.encode(contents, format, dimension, dimension, hints);
    int width = result.getWidth();
    int height = result.getHeight();
    Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);

    int[] pixels = new int[width * height];
    // All are 0, or black, by default
    for (int y = 0; y < height; y++) {
        int offset = y * width;
        for (int x = 0; x < width; x++) {
            pixels[offset + x] = result.get(x, y) ? BLACK : WHITE;
            //bitmap.setPixel(x,y,result.get(x, y) ? BLACK : WHITE);
        }
    }

    bitmap.setPixels(pixels, 0, width, 0, 0, width, height);
    return bitmap;
}
 
源代码29 项目: ScreenCapture   文件: Code93Writer.java
@Override
public BitMatrix encode(String contents,
                        BarcodeFormat format,
                        int width,
                        int height,
                        Map<EncodeHintType,?> hints) throws WriterException {
  if (format != BarcodeFormat.CODE_93) {
    throw new IllegalArgumentException("Can only encode CODE_93, but got " + format);
  }
  return super.encode(contents, format, width, height, hints);
}
 
源代码30 项目: react-native-esc-pos   文件: PrinterService.java
private ByteArrayOutputStream generateQRCodeByteArrayOutputStream(String value, int size) throws QRCodeException {
    try {
        BitMatrix result = new QRCodeWriter().encode(value, BarcodeFormat.QR_CODE, size, size, null);
        Bitmap qrcode = BitMatrixUtils.convertToBitmap(result);
        return generateImageByteArrayOutputStream(qrcode);
    } catch (IllegalArgumentException | WriterException | IOException e) {
        // Unsupported format
        throw new QRCodeException("QRCode generation error", e);
    }
}
 
 类所在包
 类方法
 同包方法