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


Java MultiFormatWriter.encode方法代码示例

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


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

示例1: encodeStringToBitmap

import com.google.zxing.MultiFormatWriter; //导入方法依赖的package包/类
public static Bitmap encodeStringToBitmap(String contents) throws WriterException {
    //Null check, just b/c
    if (contents == null) {
        return null;
    }
    Map<EncodeHintType, Object> hints = new EnumMap<>(EncodeHintType.class);
    hints.put(EncodeHintType.CHARACTER_SET, "UTF-8");
    MultiFormatWriter writer = new MultiFormatWriter();
    BitMatrix result = writer.encode(contents, BarcodeFormat.PDF_417, 700, 900, hints);
    int width = result.getWidth();
    int height = result.getHeight();
    int[] pixels = new int[width * height];
    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) ? 0xFF000000 : 0xFFFFFFFF;
        }
    }
    Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    bitmap.setPixels(pixels, 0, width, 0, 0, width, height);
    return bitmap;
}
 
开发者ID:theandrewlane,项目名称:super-contacts,代码行数:23,代码来源:BarcodeWriter.java

示例2: encodeAsBitmap

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

示例3: encodeAsBitmap

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

示例4: encodeAsBitmap

import com.google.zxing.MultiFormatWriter; //导入方法依赖的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, 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;
}
 
开发者ID:manuelsc,项目名称:Lunary-Ethereum-Wallet,代码行数:27,代码来源:QREncoder.java

示例5: createNewQR

import com.google.zxing.MultiFormatWriter; //导入方法依赖的package包/类
private Bitmap createNewQR(String s) {
    MultiFormatWriter mFW = new MultiFormatWriter();
    Bitmap bM = null;

    int px = (int) GraphicUtils.dpToPx(250);

    try {
        BitMatrix bitM = mFW.encode(s, BarcodeFormat.QR_CODE, px, px);
        bM = Bitmap.createBitmap(px, px, Bitmap.Config.ARGB_8888);
        for (int i = 0; i < px; i++) {
            for (int j = 0; j < px; j++) {
                int c = (bitM.get(i, j)) ? Color.BLACK : Color.WHITE;
                bM.setPixel(i, j, c);
            }
        }
    } catch (WriterException e) {
        Utils.logError(e);
    }
    return bM;
}
 
开发者ID:LCA311,项目名称:leoapp-sources,代码行数:21,代码来源:QRWriteTask.java

示例6: writeInfoToJpgBuffImg

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

示例7: generateBarcode

import com.google.zxing.MultiFormatWriter; //导入方法依赖的package包/类
private Bitmap generateBarcode(String card, int w, int h) {
    MultiFormatWriter writer = new MultiFormatWriter();

    try {
        BitMatrix bitMatrix = writer.encode(card, BarcodeFormat.CODE_39, w, h);
        int width = bitMatrix.getWidth();
        int height = bitMatrix.getHeight();
        Bitmap bmp = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
        for (int x = 0; x < width; x++) {
            for (int y = 0; y < height; y++) {
                bmp.setPixel(x, y, bitMatrix.get(x, y) ? Color.BLACK : Color.WHITE);
            }
        }
        Matrix matrix = new Matrix();
        matrix.postRotate(90);
        return Bitmap.createBitmap(bmp, 0, 0, width, height, matrix, true);
    } catch (WriterException e) {
        e.printStackTrace();
        return null;
    }
}
 
开发者ID:AIDEA775,项目名称:UNCmorfi,代码行数:22,代码来源:BalanceBackend.java

示例8: writeInfoToJpgBuff

import com.google.zxing.MultiFormatWriter; //导入方法依赖的package包/类
/**
 * 二维码信息写成JPG BufferedImage
 * @param content 二维码信息
 * @return JPG BufferedImage
 */
public static BufferedImage writeInfoToJpgBuff(String content){
   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, 250, 250, hints);
	re=MatrixToImageWriter.toBufferedImage(bitMatrix);
} catch (Exception e) {
	e.printStackTrace();
}	 
   
 return re;
}
 
开发者ID:egzosn,项目名称:pay-java-parent,代码行数:22,代码来源:MatrixToImageWriter.java

示例9: generate

import com.google.zxing.MultiFormatWriter; //导入方法依赖的package包/类
public Bitmap generate(BarcodeRequest barcodeRequest) {
    MultiFormatWriter multiFormatWriter = new MultiFormatWriter();
    Map<EncodeHintType, Object> hints = new EnumMap<>(EncodeHintType.class);
    hints.put(EncodeHintType.CHARACTER_SET, barcodeRequest.getCharacterSet());
    try {
        BitMatrix bitMatrix = multiFormatWriter.encode(
                barcodeRequest.getBarcodeText(),
                barcodeRequest.getBarcodeFormat(),
                barcodeRequest.getWidth(),
                barcodeRequest.getHeight(),
                hints);
        return convertBitMatrixToBitmap(bitMatrix, barcodeRequest.getForegroundColor(), barcodeRequest.getBackgroundColor());
    } catch (WriterException e) {
        Log.e(TAG, "Caught com.google.zxing.WriterException", e);
    }
    return null;
}
 
开发者ID:BottleRocketStudios,项目名称:Android-Barcode,代码行数:18,代码来源:BarcodeBitmapGenerator.java

示例10: printImage

import com.google.zxing.MultiFormatWriter; //导入方法依赖的package包/类
/**
 * Writes the image file to the output stream.
 *
 * @param graph    the object graph
 * @param exchange the camel exchange
 * @param stream   the output stream
 */
private void printImage(final Exchange exchange, final Object graph, final OutputStream stream) throws Exception {
    final String payload = ExchangeHelper
            .convertToMandatoryType(exchange, String.class, graph);
    final MultiFormatWriter writer = new MultiFormatWriter();

    // set values
    final String type = this.params.getType().toString();

    // create code image  
    final BitMatrix matrix = writer.encode(
            payload,
            this.params.getFormat(),
            this.params.getWidth(),
            this.params.getHeight(),
            writerHintMap);

    // write image back to stream
    MatrixToImageWriter.writeToStream(matrix, type, stream);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:27,代码来源:BarcodeDataFormat.java

示例11: main

import com.google.zxing.MultiFormatWriter; //导入方法依赖的package包/类
@Test
    public void main() {

        try {
            String content = "这是测试xing二维码生成";
//        String path = "D:/tt";
            String path = "D:/tmp/";
            MultiFormatWriter multiFormatWriter = new MultiFormatWriter();
            Map hints = new HashMap();
            //内容所使用编码
            hints.put(EncodeHintType.CHARACTER_SET, "UTF-8");
            BitMatrix bitMatrix = multiFormatWriter.encode(content, BarcodeFormat.QR_CODE, 200, 200, hints);
            //生成二维码
            File outputFile = new File(path, "14.jpg");
            QrCodeWriter.writeToFile(bitMatrix, "jpg", outputFile);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
 
开发者ID:whyDK37,项目名称:pinenut,代码行数:20,代码来源:QrCodeTest.java

示例12: encodeAsBitmap

import com.google.zxing.MultiFormatWriter; //导入方法依赖的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, 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;
}
 
开发者ID:FauDroids,项目名称:FlippyPairs,代码行数:27,代码来源:QRCodeEncoder.java

示例13: renderCode

import com.google.zxing.MultiFormatWriter; //导入方法依赖的package包/类
private void renderCode(H.Response response) {
    response.contentType("image/png");
    Map<EncodeHintType, Object> hints = new HashMap<>();
    hints.put(EncodeHintType.CHARACTER_SET, Act.appConfig().encoding());
    hints.put(EncodeHintType.MARGIN, 0);
    ErrorCorrectionLevel level = errorCorrectionLevel();
    if (null != level) {
        hints.put(EncodeHintType.ERROR_CORRECTION, level);
    }
    MultiFormatWriter writer = new MultiFormatWriter();
    try {
        BitMatrix bitMatrix = writer.encode(getMessage(), barcodeFormat(), width, height, hints);
        MatrixToImageWriter.writeToStream(bitMatrix, "png", response.outputStream());
    } catch (Exception e) {
        throw E.unexpected(e);
    }
}
 
开发者ID:actframework,项目名称:actframework,代码行数:18,代码来源:ZXingResult.java

示例14: encodeAsBitmap

import com.google.zxing.MultiFormatWriter; //导入方法依赖的package包/类
public Bitmap encodeAsBitmap() throws WriterException {
    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:dimagi,项目名称:commcare-android,代码行数:25,代码来源:QRCodeEncoder.java

示例15: encodeAsBitmap

import com.google.zxing.MultiFormatWriter; //导入方法依赖的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, 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;
}
 
开发者ID:alouanemed,项目名称:EvGuide,代码行数:27,代码来源:QRCodeEncoder.java


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