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


Java MatrixToImageWriter类代码示例

本文整理汇总了Java中com.google.zxing.client.j2se.MatrixToImageWriter的典型用法代码示例。如果您正苦于以下问题:Java MatrixToImageWriter类的具体用法?Java MatrixToImageWriter怎么用?Java MatrixToImageWriter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


MatrixToImageWriter类属于com.google.zxing.client.j2se包,在下文中一共展示了MatrixToImageWriter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getQR

import com.google.zxing.client.j2se.MatrixToImageWriter; //导入依赖的package包/类
/**
 * Method to get the JavaFX Image QR code for easy input of address
 * @param width width of the image
 * @param height height of the image
 * @return Java FX Image
 * @throws IOException Either when there is an encoding error or java's reserved memory is overwritten.
 * @throws WriterException When ZXING encounters an error.
 */
public Image getQR(int width, int height) throws IOException, WriterException{
    String charset = "UTF-8";
    Map hintMap = new HashMap();
    hintMap.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.M);

    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    BitMatrix matrix = new MultiFormatWriter().encode(new String(cryptoAddress.getBytes(charset), charset), BarcodeFormat.QR_CODE, width, height, hintMap);
    MatrixToImageWriter.writeToStream(matrix, "png", stream);
    stream.flush();

    byte[] data = stream.toByteArray();
    stream.close();

    return new Image(new ByteArrayInputStream(data));
}
 
开发者ID:Roxas240,项目名称:CryptoPayAPI,代码行数:24,代码来源:CryptoClient.java

示例2: getQRCodeImge

import com.google.zxing.client.j2se.MatrixToImageWriter; //导入依赖的package包/类
/**
 * 将内容contents生成长为width,宽为width的图片,返回刘文静
 */
public static ServletOutputStream getQRCodeImge(String contents, int width, int height) throws IOException {
    ServletOutputStream stream = null;
    try {
        Map<EncodeHintType, Object> hints = Maps.newHashMap();
        hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.M);
        hints.put(EncodeHintType.CHARACTER_SET, "UTF8");
        BitMatrix bitMatrix = new MultiFormatWriter().encode(contents, BarcodeFormat.QR_CODE, width, height, hints);
        MatrixToImageWriter.writeToStream(bitMatrix, "png", stream);
        return stream;
    } catch (Exception e) {
        log.error("create QR code error!", e);
        return null;
    } finally {
        if (stream != null) {
            stream.close();
        }
    }
}
 
开发者ID:fanqinghui,项目名称:wish-pay,代码行数:22,代码来源:ZxingUtils.java

示例3: barcode417

import com.google.zxing.client.j2se.MatrixToImageWriter; //导入依赖的package包/类
@RequestMapping(value = "/pdf417/{id}", method = RequestMethod.GET, produces = IMAGE_PNG)
public void barcode417(@PathVariable("id") String id, HttpServletResponse response) throws IOException, WriterException {
    if (!CLIENT_ID_PATTERN.matcher(id).matches()) {
        throw new InputValidationException("Invalid clientId for barcode [" + id + "]");
    }
    response.setContentType(IMAGE_PNG);
    Map<EncodeHintType, Object> hints = new HashMap<EncodeHintType, Object>() {{
        put(EncodeHintType.MARGIN, MARGIN_PIXELS);
        put(EncodeHintType.ERROR_CORRECTION, 2);
        put(EncodeHintType.PDF417_COMPACT, true);
        put(EncodeHintType.PDF417_COMPACTION, Compaction.TEXT);
    }};
    BitMatrix matrix = new MultiFormatWriter().encode(id, BarcodeFormat.PDF_417, BARCODE_WIDTH, BARCODE_HEIGHT, hints);
    BufferedImage bufferedImage = MatrixToImageWriter.toBufferedImage(matrix);
    BufferedImage croppedImage = cropImageWorkaroundDueToZxingBug(bufferedImage);
    ImageIO.write(croppedImage, "PNG", response.getOutputStream());
}
 
开发者ID:AusDTO,项目名称:citizenship-appointment-server,代码行数:18,代码来源:BarcodeController.java

示例4: encode

import com.google.zxing.client.j2se.MatrixToImageWriter; //导入依赖的package包/类
/**
 * Zxing图形码生成工具
 *
 * @param contents
 *            内容
 * @param barcodeFormat
 *            BarcodeFormat对象
 * @param format
 *            图片格式,可选[png,jpg,bmp]
 * @param width
 *            宽
 * @param height
 *            高
 * @param margin
 *            边框间距px
 * @param saveImgFilePath
 *            存储图片的完整位置,包含文件名
 * @return {boolean}
 */
public static boolean encode(String contents, BarcodeFormat barcodeFormat, Integer margin,
		ErrorCorrectionLevel errorLevel, String format, int width, int height, String saveImgFilePath) {
	Boolean bool = false;
	BufferedImage bufImg;
	Map<EncodeHintType, Object> hints = new HashMap<EncodeHintType, Object>();
	// 指定纠错等级
	hints.put(EncodeHintType.ERROR_CORRECTION, errorLevel);
	hints.put(EncodeHintType.MARGIN, margin);
	hints.put(EncodeHintType.CHARACTER_SET, "UTF-8");
	try {
		// contents = new String(contents.getBytes("UTF-8"), "ISO-8859-1");
		BitMatrix bitMatrix = new MultiFormatWriter().encode(contents, barcodeFormat, width, height, hints);
		MatrixToImageConfig config = new MatrixToImageConfig(0xFF000001, 0xFFFFFFFF);
		bufImg = MatrixToImageWriter.toBufferedImage(bitMatrix, config);
		bool = writeToFile(bufImg, format, saveImgFilePath);
	} catch (Exception e) {
		e.printStackTrace();
	}
	return bool;
}
 
开发者ID:Javen205,项目名称:IJPay,代码行数:40,代码来源:ZxingKit.java

示例5: encode

import com.google.zxing.client.j2se.MatrixToImageWriter; //导入依赖的package包/类
/**
 * 条形码编码
 */
public static BufferedImage encode(String contents, int width, int height) {
	int codeWidth = 3 + // start guard
			(7 * 6) + // left bars
			5 + // middle guard
			(7 * 6) + // right bars
			3; // end guard
	codeWidth = Math.max(codeWidth, width);
	try {
		// 原为13位Long型数字(BarcodeFormat.EAN_13),现为128位
		BitMatrix bitMatrix = new MultiFormatWriter().encode(contents, BarcodeFormat.CODE_128, codeWidth, height, null);
		return MatrixToImageWriter.toBufferedImage(bitMatrix);
	} catch (Exception e) {
		e.printStackTrace();
	}
	return null;
}
 
开发者ID:funtl,项目名称:framework,代码行数:20,代码来源:BarCodeUtils.java

示例6: createQrcode

import com.google.zxing.client.j2se.MatrixToImageWriter; //导入依赖的package包/类
public static String createQrcode(String dir, String _text) {
	String qrcodeFilePath = "";
	try {
		int qrcodeWidth = 300;
		int qrcodeHeight = 300;
		String qrcodeFormat = "png";
		HashMap<EncodeHintType, String> hints = new HashMap<EncodeHintType, String>();
		hints.put(EncodeHintType.CHARACTER_SET, "UTF-8");
		BitMatrix bitMatrix = new MultiFormatWriter().encode(_text, BarcodeFormat.QR_CODE, qrcodeWidth,
				qrcodeHeight, hints);

		BufferedImage image = new BufferedImage(qrcodeWidth, qrcodeHeight, BufferedImage.TYPE_INT_RGB);
		File qrcodeFile = new File(dir + "/" + UUID.randomUUID().toString() + "." + qrcodeFormat);
		ImageIO.write(image, qrcodeFormat, qrcodeFile);
		MatrixToImageWriter.writeToPath(bitMatrix, qrcodeFormat, qrcodeFile.toPath());
		qrcodeFilePath = qrcodeFile.getAbsolutePath();
	} catch (Exception e) {
		e.printStackTrace();
	}
	return qrcodeFilePath;
}
 
开发者ID:guokezheng,项目名称:automat,代码行数:22,代码来源:QrcodeUtil.java

示例7: barCode

import com.google.zxing.client.j2se.MatrixToImageWriter; //导入依赖的package包/类
public static void barCode(String contents,String imgPath,int width, int height) {
    int codeWidth = 3 + // start guard
            (7 * 6) + // left bars
            5 + // middle guard
            (7 * 6) + // right bars
            3; // end guard
    codeWidth = Math.max(codeWidth, width);
    try {
        BitMatrix bitMatrix = new MultiFormatWriter().encode(contents,BarcodeFormat.CODE_128, codeWidth, height, null);
        bitMatrix = deleteWhite(bitMatrix);
        MatrixToImageWriter.writeToFile(bitMatrix, "png", new File(imgPath));
    }catch (Exception e) {
    	log.error(e.getMessage());
        e.printStackTrace();
    }
}
 
开发者ID:thlws,项目名称:payment-wechat,代码行数:17,代码来源:ZxingUtil.java

示例8: encode

import com.google.zxing.client.j2se.MatrixToImageWriter; //导入依赖的package包/类
/**
 * 生成条形二维码
 */
public static byte[] encode(String contents, int width, int height, String imgPath) {
    int codeWidth = 3 + // start guard
            (7 * 6) + // left bars
            5 + // middle guard
            (7 * 6) + // right bars
            3; // end guard
    codeWidth = Math.max(codeWidth, width);
    byte[] buf = null;
    try {
        BitMatrix bitMatrix = new MultiFormatWriter().encode(contents,
                BarcodeFormat.CODE_128, codeWidth, height, null);
        BufferedImage image = MatrixToImageWriter.toBufferedImage(bitMatrix);
        ByteArrayOutputStream out = new ByteArrayOutputStream();
      ImageIO.write(image, FORMAT_NAME, out);
      out.close();
buf = out.toByteArray();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return buf;
}
 
开发者ID:Fetax,项目名称:Fetax-AI,代码行数:25,代码来源:CodeUtil.java

示例9: createImage

import com.google.zxing.client.j2se.MatrixToImageWriter; //导入依赖的package包/类
/**
 *
 * @param path 完整的路径包括文件名
 * @param width 图片宽
 * @param height 图片高
 * @param contents 内容
 */
public static void createImage(String path,int width,int height,String contents){
	String format = "png";
	//定义二维码的参数
	HashMap hints = new HashMap();
	hints.put(EncodeHintType.AZTEC_LAYERS, "utf-8");//设置编码
	hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.M);//设置容错等级: L M Q H
	hints.put(EncodeHintType.MARGIN,1);//设置边距

	//生成文件
	try {
		BitMatrix bitMatrix = new MultiFormatWriter().encode(contents, BarcodeFormat.QR_CODE, width, height,hints);
		Path file = new File(path).toPath();
		MatrixToImageWriter.writeToPath(bitMatrix, format, file);
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
开发者ID:Kuangcp,项目名称:JavaToolKit,代码行数:25,代码来源:CreateQRCode.java

示例10: encode

import com.google.zxing.client.j2se.MatrixToImageWriter; //导入依赖的package包/类
/**
 * 条形码编码
 * <p>
 * String imgPath = "target/zxing.png";
 * String contents = "6923450657713";
 * int width = 105, height = 50;
 * ZxingHelper.encode(contents, width, height, imgPath);
 *
 * @param contents 内容
 * @param width    宽度
 * @param height   高度
 * @param imgPath  生成图片路径
 */
public static void encode(String contents, int width, int height, String imgPath) {
    int codeWidth = 3 + // start guard
        (7 * 6) + // left bars
        5 + // middle guard
        (7 * 6) + // right bars
        3; // end guard
    codeWidth = Math.max(codeWidth, width);
    try {
        BitMatrix bitMatrix = new MultiFormatWriter().encode(contents,
            BarcodeFormat.EAN_13, codeWidth, height, null);

        MatrixToImageWriter
            .writeToPath(bitMatrix, "png", new File(imgPath).toPath());

    } catch (Exception e) {
        LOGGER.error("生成条形码错误", e);
    }
}
 
开发者ID:ruyangit,项目名称:angit,代码行数:32,代码来源:ZxingHelper.java

示例11: encode2

import com.google.zxing.client.j2se.MatrixToImageWriter; //导入依赖的package包/类
/**
 * 二维码编码
 * <p>
 * String imgPath2 = "target/zxing2.png";
 * String contents2 = "Hello Zxing!";
 * int width2 = 300, height2 = 300;
 * ZxingHelper.encode2(contents2, width2, height2, imgPath2);
 *
 * @param contents 内容
 * @param width    宽度
 * @param height   高度
 * @param imgPath  生成图片路径
 */
public static void encode2(String contents, int width, int height, String imgPath) {
    EnumMap<EncodeHintType, Object> hints = new EnumMap<>(EncodeHintType.class);
    // 指定纠错等级
    hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.L);
    // 指定编码格式
    hints.put(EncodeHintType.CHARACTER_SET, "GBK");
    try {
        BitMatrix bitMatrix = new MultiFormatWriter().encode(contents,
            BarcodeFormat.QR_CODE, width, height, hints);

        MatrixToImageWriter
            .writeToPath(bitMatrix, "png", new File(imgPath).toPath());

    } catch (Exception e) {
        LOGGER.error("生成二维码错误", e);
    }
}
 
开发者ID:ruyangit,项目名称:angit,代码行数:31,代码来源:ZxingHelper.java

示例12: writeInfoToJpgBuffImg

import com.google.zxing.client.j2se.MatrixToImageWriter; //导入依赖的package包/类
/**
 * 二维码信息写成JPG BufferedImage
 *
 * @param content
 * @param width
 * @param height
 * @return
 */
public static BufferedImage writeInfoToJpgBuffImg(String content, int width, int height) {
    if (width < 250) {
        width = 250;
    }
    if (height < 250) {
        height = 250;
    }
    BufferedImage re = null;

    MultiFormatWriter multiFormatWriter = new MultiFormatWriter();
    Map hints = new HashMap();
    hints.put(EncodeHintType.CHARACTER_SET, "UTF-8");
    try {
        BitMatrix bitMatrix = multiFormatWriter.encode(content,
                BarcodeFormat.QR_CODE, width, height, hints);
        re = MatrixToImageWriter.toBufferedImage(bitMatrix);
    } catch (Exception e) {
        e.printStackTrace();
    }

    return re;
}
 
开发者ID:fanqinghui,项目名称:wish-pay,代码行数:31,代码来源:ZxingUtils.java

示例13: createQRCode

import com.google.zxing.client.j2se.MatrixToImageWriter; //导入依赖的package包/类
/**二维码的生成*/
private void createQRCode(HttpServletResponse response){
	/**设置二维码的参数*/
	Map<EncodeHintType, Object> hints = new HashMap<EncodeHintType, Object>();
	// 内容所使用编码
	hints.put(EncodeHintType.CHARACTER_SET, "utf-8");
	// 留白区域大小
	hints.put(EncodeHintType.MARGIN, margin);
	try {
		BitMatrix bitMatrix = new MultiFormatWriter().encode(content,BarcodeFormat.QR_CODE,width,height,hints);
		// 输出二维码
		MatrixToImageWriter.writeToStream(bitMatrix, format, response.getOutputStream());
	} catch (Exception e) {
		System.out.println("生成二维码异常!"+e.toString());
	}
}
 
开发者ID:zhiqiang94,项目名称:BasicsProject,代码行数:17,代码来源:ZxingServlet.java

示例14: createBarCode

import com.google.zxing.client.j2se.MatrixToImageWriter; //导入依赖的package包/类
/**条形码的生成*/
private void createBarCode(HttpServletResponse response){
	int codeWidth = 3 + // start guard
			(7 * 6) + // left bars
			5 + // middle guard
			(7 * 6) + // right bars
			3; // end guard
	codeWidth = Math.max(codeWidth, width);
	try {
		BitMatrix bitMatrix = new MultiFormatWriter().encode(content,BarcodeFormat.CODE_128, codeWidth, height, null);
		// 条形码
		MatrixToImageWriter.writeToStream(bitMatrix, format, response.getOutputStream());
	} catch (Exception e) {
		System.out.println("生成条形码异常!"+e.toString());
	}
}
 
开发者ID:zhiqiang94,项目名称:BasicsProject,代码行数:17,代码来源:ZxingServlet.java

示例15: createQrcode

import com.google.zxing.client.j2se.MatrixToImageWriter; //导入依赖的package包/类
/**
 * 二维码生成 ,储存地址qrcodeFilePath
 * 
 * @param text 二维码内容
 * @return Base64Code String
 */
@SuppressWarnings("restriction")
public String createQrcode(String text){
	String Imgencode="";
       byte[] imageByte=null;
       String formatName="PNG";
       try {
       	//
           int qrcodeWidth = 300;
           int qrcodeHeight = 300;
           HashMap<EncodeHintType, String> hints = new HashMap<EncodeHintType, String>();
           hints.put(EncodeHintType.CHARACTER_SET, "UTF-8");
           BitMatrix bitMatrix = new MultiFormatWriter().encode(text, BarcodeFormat.QR_CODE, qrcodeWidth, qrcodeHeight, hints);
          
           ByteArrayOutputStream out = new ByteArrayOutputStream();
           BufferedImage bufferedImage = MatrixToImageWriter.toBufferedImage(bitMatrix);
           ImageIO.write(bufferedImage, formatName, out);
           imageByte=out.toByteArray();
           Imgencode = new sun.misc.BASE64Encoder().encode(imageByte);
       } catch (Exception e) {
           e.printStackTrace();
       }
       return Imgencode;
   }
 
开发者ID:noseparte,项目名称:Spring-Boot-Server,代码行数:30,代码来源:Qrcode.java


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