本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
}
示例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;
}
示例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;
}
示例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);
}
示例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();
}
}
示例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;
}
示例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);
}
}
示例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;
}
示例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;
}