當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。