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


Java EncodeHintType类代码示例

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


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

示例1: Create2DCode

import com.google.zxing.EncodeHintType; //导入依赖的package包/类
/**
 * 用字符串生成二维码
 * 
 * @param str
 * @author J!nl!n
 * @return
 * @throws WriterException
 */
public Bitmap Create2DCode(String str) 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, 480, 480, hints);
	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] = 0xff000000;
			}
		}
	}

	Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
	// 通过像素数组生成bitmap,具体参考api
	bitmap.setPixels(pixels, 0, width, 0, 0, width, height);
	return bitmap;
}
 
开发者ID:wp521,项目名称:MyFire,代码行数:31,代码来源:ScanMainActivity.java

示例2: getQR

import com.google.zxing.EncodeHintType; //导入依赖的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

示例3: getQR

import com.google.zxing.EncodeHintType; //导入依赖的package包/类
public static Bitmap getQR(final byte[] content, final int size) {
    final QRCodeWriter writer = new QRCodeWriter();
    try {
        final Map<EncodeHintType, Object> encodingHints = new HashMap<>();
        encodingHints.put(EncodeHintType.CHARACTER_SET, "UTF-8");
        encodingHints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);

        final BitMatrix encoding = writer.encode(Utils.makeQR(content), BarcodeFormat.QR_CODE, size, size, encodingHints);
        final Bitmap bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);

        for (int i = 0; i < size; i++) {
            for (int j = 0; j < size; j++) {
                bitmap.setPixel(i, j, encoding.get(i, j) ? COLOR_DARK : COLOR_LIGHT);
            }
        }

        return bitmap;
    } catch (WriterException e) {
        Log.e("QRUtils", "Failed to get QR code", e);
    }
    return null;
}
 
开发者ID:mDL-ILP,项目名称:mDL-ILP,代码行数:23,代码来源:QRUtils.java

示例4: createQRCode

import com.google.zxing.EncodeHintType; //导入依赖的package包/类
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;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:22,代码来源:EncodingHandler.java

示例5: encode

import com.google.zxing.EncodeHintType; //导入依赖的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

示例6: createQRCode

import com.google.zxing.EncodeHintType; //导入依赖的package包/类
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;
}
 
开发者ID:guxiaonian,项目名称:MeiLa_GNN,代码行数:22,代码来源:EncodingHandler.java

示例7: createImage

import com.google.zxing.EncodeHintType; //导入依赖的package包/类
/**
 * 创建二维码
 *
 * @param size         二维码尺寸
 * @param content      二维码内容
 * @param logoPath     Logo地址
 * @param needCompress 是否压缩
 * @return
 * @throws Exception
 */
private static BufferedImage createImage(int size, String content, String logoPath, boolean needCompress) throws Exception {
	Hashtable<EncodeHintType, Object> hints = new Hashtable<EncodeHintType, Object>();
	hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
	hints.put(EncodeHintType.CHARACTER_SET, CHARSET);
	hints.put(EncodeHintType.MARGIN, 1);
	BitMatrix bitMatrix = new MultiFormatWriter().encode(content, BarcodeFormat.QR_CODE, size, size, hints);
	int width = bitMatrix.getWidth();
	int height = bitMatrix.getHeight();
	BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
	for (int x = 0; x < width; x++) {
		for (int y = 0; y < height; y++) {
			image.setRGB(x, y, bitMatrix.get(x, y) ? 0xFF000000 : 0xFFFFFFFF);
		}
	}
	if (logoPath == null || "".equals(logoPath)) {
		return image;
	}
	// 插入图片
	QRCodeUtils.insertImage(size, image, logoPath, needCompress);
	return image;
}
 
开发者ID:funtl,项目名称:framework,代码行数:32,代码来源:QRCodeUtils.java

示例8: encodeAsBitmap

import com.google.zxing.EncodeHintType; //导入依赖的package包/类
public Bitmap encodeAsBitmap() throws WriterException {
    if (!encoded) return null;

    Map<EncodeHintType, Object> hints = null;
    String encoding = guessAppropriateEncoding(contents);
    hints = new EnumMap<EncodeHintType, Object>(EncodeHintType.class);
    if (encoding != null) {
        
        hints.put(EncodeHintType.CHARACTER_SET, encoding);
    }
    hints.put(EncodeHintType.MARGIN, 2); /* default = 4 */  
    
    
    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;
}
 
开发者ID:PhilippC,项目名称:keepass2android,代码行数:31,代码来源:QRCodeEncoder.java

示例9: encodeAsBitmap

import com.google.zxing.EncodeHintType; //导入依赖的package包/类
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();
    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;
}
 
开发者ID:uhuru-mobile,项目名称:mobile-store,代码行数:27,代码来源:QRCodeEncoder.java

示例10: createQRCode

import com.google.zxing.EncodeHintType; //导入依赖的package包/类
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;
}
 
开发者ID:kkyflying,项目名称:CodeScaner,代码行数:22,代码来源:EncodingHandler.java

示例11: createQRCode

import com.google.zxing.EncodeHintType; //导入依赖的package包/类
public static Bitmap createQRCode(String content, int widthAndHeight) {
    if (TextUtils.isEmpty(content)) return null;
    try {
        Hashtable<EncodeHintType, Object> hints = new Hashtable<EncodeHintType, Object>();
        hints.put(EncodeHintType.CHARACTER_SET, "utf-8");
        //Fault tolerance level. MAX
        hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
        //Set the width of the blank margin.
        hints.put(EncodeHintType.MARGIN, 0);
        BitMatrix matrix = new MultiFormatWriter().encode(content, 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] = 0xff000000;
                }
            }
        }
        Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
        bitmap.setPixels(pixels, 0, width, 0, 0, width, height);

        return bitmap;
    } catch (WriterException e) {
        e.printStackTrace();
    }
    return null;
}
 
开发者ID:Jusenr,项目名称:zxing_qrcode_demo,代码行数:32,代码来源:EncodingHandler.java

示例12: createQRCode

import com.google.zxing.EncodeHintType; //导入依赖的package包/类
/**
 * 根据内容生成二维码数据
 * @param content 二维码文字内容[为了信息安全性,一般都要先进行数据加密]
 * @param width 二维码照片宽度
 * @param height 二维码照片高度
 * @return
 */
public static BitMatrix createQRCode(String content, int width, int height){
	Hashtable<EncodeHintType, Object> hints = new Hashtable<EncodeHintType, Object>();   
	//设置字符编码
       hints.put(EncodeHintType.CHARACTER_SET, "utf-8");  
       // 指定纠错等级
	hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
	hints.put(EncodeHintType.MARGIN, 1);
       BitMatrix matrix = null;  
       try {  
           matrix = new MultiFormatWriter().encode(content, BarcodeFormat.QR_CODE, width, height, hints); 
       } catch (WriterException e) {  
           e.printStackTrace();  
       }
       
       return matrix;
}
 
开发者ID:onsoul,项目名称:os,代码行数:24,代码来源:MatrixToImageWriterEx.java

示例13: createQRCode

import com.google.zxing.EncodeHintType; //导入依赖的package包/类
private Bitmap createQRCode(String str, int widthAndHeight)
        throws WriterException {
    Hashtable<EncodeHintType, String> hints = new Hashtable<EncodeHintType, String>();
    hints.put(EncodeHintType.CHARACTER_SET, "utf-8");// 使用utf8编码
    BitMatrix matrix = new MultiFormatWriter().encode(str,
            BarcodeFormat.QR_CODE, widthAndHeight, widthAndHeight, hints);// 这里需要把hints传进去,否则会出现中文乱码
    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;
            } else {// 其他部分则使用白色
                pixels[y * width + x] = WHITE;
            }
        }
    }
    //生成bitmap
    Bitmap bitmap = Bitmap.createBitmap(width, height,
            Bitmap.Config.ARGB_8888);
    bitmap.setPixels(pixels, 0, width, 0, 0, width, height);
    return bitmap;
}
 
开发者ID:lzmlsfe,项目名称:19porn,代码行数:27,代码来源:InvitationActivity.java

示例14: createQRCode

import com.google.zxing.EncodeHintType; //导入依赖的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

示例15: createQrcode

import com.google.zxing.EncodeHintType; //导入依赖的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


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