當前位置: 首頁>>代碼示例>>Java>>正文


Java MatrixToImageWriter.toBufferedImage方法代碼示例

本文整理匯總了Java中com.google.zxing.client.j2se.MatrixToImageWriter.toBufferedImage方法的典型用法代碼示例。如果您正苦於以下問題:Java MatrixToImageWriter.toBufferedImage方法的具體用法?Java MatrixToImageWriter.toBufferedImage怎麽用?Java MatrixToImageWriter.toBufferedImage使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.google.zxing.client.j2se.MatrixToImageWriter的用法示例。


在下文中一共展示了MatrixToImageWriter.toBufferedImage方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例7: toSingleQrCodeBufferedImage

import com.google.zxing.client.j2se.MatrixToImageWriter; //導入方法依賴的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

示例8: 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
     */
    public Boolean encode(String contents, BarcodeFormat barcodeFormat, Integer margin, ErrorCorrectionLevel errorLevel, String format, int width, int height, String saveImgFilePath) {
        Boolean bool;
        BufferedImage bufImg;
        Map<EncodeHintType, Object> hints = new HashMap<>();
        // 指定糾錯等級
        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 = this.writeToFile(bufImg, format, saveImgFilePath);
        } catch (Throwable t) {
            log.error("encode-ex:{}", t);
            throw Throwables.propagate(t);
        }
        return bool;
    }
 
開發者ID:gumutianqi,項目名稱:jfinal-plus,代碼行數:33,代碼來源:ZxingKit.java

示例9: getProductEAN

import com.google.zxing.client.j2se.MatrixToImageWriter; //導入方法依賴的package包/類
@ResponseBody
@RequestMapping(method = RequestMethod.GET, value = "/{productId}/ean")
public ResponseEntity<?> getProductEAN(@PathVariable String productId) throws WriterException, IOException {
    Product product = repository.findOne(productId);
    if (product == null) {
        return ResponseEntity.notFound().build();
    }
    EAN13Writer ean13Writer = new EAN13Writer();
    BitMatrix matrix = ean13Writer.encode(product.getEan(), BarcodeFormat.EAN_13, 300, 200);
    BufferedImage bufferedImage = MatrixToImageWriter.toBufferedImage(matrix);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ImageIO.write(bufferedImage, "png", baos);
    byte[] imageData = baos.toByteArray();
    ByteArrayResource byteArrayResource = new ByteArrayResource(imageData);
    return ResponseEntity.ok().contentType(MediaType.IMAGE_PNG).body(byteArrayResource);
}
 
開發者ID:thomasletsch,項目名稱:moserp,代碼行數:17,代碼來源:ProductController.java

示例10: setDriver

import com.google.zxing.client.j2se.MatrixToImageWriter; //導入方法依賴的package包/類
private void setDriver(String libraryID)
{
	if(libraryID == null)
	{
		this.image = null;
		repaint();
		return;
	}
	BitMatrix matrix;
	try
	{
		matrix = new QRCodeWriter().encode(QR_MESSAGE_PREFIX + libraryID, com.google.zxing.BarcodeFormat.QR_CODE, WIDTH, HEIGHT);
	}
	catch(@SuppressWarnings("unused") WriterException e)
	{
		this.image = null;
		repaint();
		return;
	}
	
	this.image = MatrixToImageWriter.toBufferedImage(matrix);
	repaint();
	return;
}
 
開發者ID:langmo,項目名稱:youscope,代碼行數:25,代碼來源:ManageAddDeviceFrame.java

示例11: toByteArray

import com.google.zxing.client.j2se.MatrixToImageWriter; //導入方法依賴的package包/類
private static byte[] toByteArray(final BitMatrix matrix, final String imageFormat)
{
	//
	// Create image from BitMatrix
	final BufferedImage image = MatrixToImageWriter.toBufferedImage(matrix);

	// Convert BufferedImage to imageFormat and write it into the stream
	try
	{
		final ByteArrayOutputStream out = new ByteArrayOutputStream();
		ImageIO.write(image, imageFormat, out);
		return out.toByteArray();
	}
	catch (final IOException ex)
	{
		throw new AdempiereException("Failed creating " + imageFormat + " image", ex);
	}

}
 
開發者ID:metasfresh,項目名稱:metasfresh,代碼行數:20,代碼來源:BarcodeRestController.java

示例12: generateQRCode

import com.google.zxing.client.j2se.MatrixToImageWriter; //導入方法依賴的package包/類
private void generateQRCode(String contents) {
        QRCodeWriter writer = new QRCodeWriter();
        BitMatrix bitMatrix = null;
        try {
            bitMatrix = writer.encode(contents, BarcodeFormat.QR_CODE, Integer.parseInt(width.getText()), Integer.parseInt(height.getText()));
            BufferedImage image = MatrixToImageWriter.toBufferedImage(bitMatrix);

            setImage(image);
        } catch (WriterException e) {
            e.printStackTrace();
        }

//		setSize(new Dimension(Math.min(300, Integer.parseInt(width.getText())), Math.min(400, Integer.parseInt(height.getText()))));
//		setPreferredSize(new Dimension(Math.min(300, Integer.parseInt(width.getText())), Math.min(400, Integer.parseInt(height.getText()))));
//		setMinimumSize(new Dimension(Math.min(300, Integer.parseInt(width.getText())), Math.min(400, Integer.parseInt(height.getText()))));
//		setMaximumSize(new Dimension(Math.min(300, Integer.parseInt(width.getText())), Math.min(400, Integer.parseInt(height.getText()))));
    }
 
開發者ID:YangMann,項目名稱:drone-slam,代碼行數:18,代碼來源:QRCodeGeneratorPanel.java

示例13: createQRCode

import com.google.zxing.client.j2se.MatrixToImageWriter; //導入方法依賴的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

示例14: setup

import com.google.zxing.client.j2se.MatrixToImageWriter; //導入方法依賴的package包/類
@Parameters(name = "{0}")
public static Collection<Object[]> setup() {
  List<Object[]> qrcodes = Lists.newArrayList();

  long seed = System.currentTimeMillis();
  Random rand = new Random(seed);
  for(int i = 0; i < COUNT; i++ ){
    byte[] bytes = new byte[nextNatural(rand) % 2048];
    rand.nextBytes(bytes);
    int height = 200 + (nextNatural(rand) % 7) * 100;
    int width = 200 + (nextNatural(rand) % 7) * 100;

    Transmit t = new Transmit(height, width);
    BitMatrix bmap = t.bytesToQRCode(bytes, ErrorCorrectionLevel.L);

    BufferedImage newCode = MatrixToImageWriter.toBufferedImage(bmap);

    qrcodes.add(new Object[] { "seed: "+ seed + ": "+i
                             , newCode
    });
  }
  return qrcodes;
}
 
開發者ID:creswick,項目名稱:StreamingQR,代碼行數:24,代碼來源:RandomQRDecodeTest.java

示例15: makeQRCode

import com.google.zxing.client.j2se.MatrixToImageWriter; //導入方法依賴的package包/類
public BufferedImage makeQRCode(byte[] data) {

        try {
            Hashtable<EncodeHintType, ErrorCorrectionLevel> hints = new Hashtable<>();
            hints.put(EncodeHintType.ERROR_CORRECTION, (errorCorrectionLevel == 0) ? ErrorCorrectionLevel.L
                    : (errorCorrectionLevel == 1) ? ErrorCorrectionLevel.M
                            : (errorCorrectionLevel == 2) ? ErrorCorrectionLevel.Q
                                    : (errorCorrectionLevel == 3) ? ErrorCorrectionLevel.H
                                            : null);
            BitMatrix matrix = new QRCodeWriter().encode(new String(data, Charset.forName("ISO-8859-1")),
                    com.google.zxing.BarcodeFormat.QR_CODE, QRSize, QRSize, hints);
            dataSendLength = data.length;
            qrCode = MatrixToImageWriter.toBufferedImage(matrix);
            return qrCode;
        } catch (WriterException ex) {
            ex.printStackTrace();
            return null;
        }
    }
 
開發者ID:anderson-,項目名稱:Eye-Fi,代碼行數:20,代碼來源:EyeFi.java


注:本文中的com.google.zxing.client.j2se.MatrixToImageWriter.toBufferedImage方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。