本文整理汇总了Java中com.google.zxing.WriterException.printStackTrace方法的典型用法代码示例。如果您正苦于以下问题:Java WriterException.printStackTrace方法的具体用法?Java WriterException.printStackTrace怎么用?Java WriterException.printStackTrace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.zxing.WriterException
的用法示例。
在下文中一共展示了WriterException.printStackTrace方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onCreate
import com.google.zxing.WriterException; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_send);
Intent intent = getIntent();
String address = intent.getStringExtra("address");
String amount = intent.getStringExtra("value");
String url = "zcash:"+address+"?amount="+amount;
TextView urltextview = (TextView)findViewById(R.id.textViewReceiveURL);
urltextview.setText(url);
try {
Bitmap bmp = encodeAsBitmap(url);
ImageView view = (ImageView)findViewById(R.id.imageViewReceive);
view.setImageBitmap(bmp);
} catch (WriterException e) {
e.printStackTrace();
}
}
示例2: updateQrCode
import com.google.zxing.WriterException; //导入方法依赖的package包/类
private void updateQrCode(String qrData) {
DisplayMetrics displayMetrics = new DisplayMetrics();
WindowManager wm = (WindowManager) getActivity().getSystemService(Context.WINDOW_SERVICE); // the results will be higher than using the activity context object or the getWindowManager() shortcut
wm.getDefaultDisplay().getMetrics(displayMetrics);
int screenWidth = displayMetrics.widthPixels;
int screenHeight = displayMetrics.heightPixels;
int qrCodeDimension = screenWidth > screenHeight ? screenHeight : screenWidth;
QRCodeEncoder qrCodeEncoder = new QRCodeEncoder(qrData, null,
Contents.Type.TEXT, BarcodeFormat.QR_CODE.toString(), qrCodeDimension);
try {
mBitmap = qrCodeEncoder.encodeAsBitmap();
mImageView.setImageBitmap(mBitmap);
mImageView.setVisibility(View.VISIBLE);
mErrorView.setVisibility(View.GONE);
} catch (WriterException e) {
e.printStackTrace();
mErrorView.setText("Error: "+e.getMessage());
mErrorView.setVisibility(View.VISIBLE);
mImageView.setVisibility(View.GONE);
}
}
示例3: printQRCodeInTerminal
import com.google.zxing.WriterException; //导入方法依赖的package包/类
/**
* 关于Ansi Color的信息,参考:http://www.lihaoyi.com/post/BuildyourownCommandLinewithANSIescapecodes.html
*
* @param text
*/
public static void printQRCodeInTerminal(String text) {
int qrcodeWidth = 400;
int qrcodeHeight = 400;
HashMap<EncodeHintType, String> hints = new HashMap<>();
hints.put(EncodeHintType.CHARACTER_SET, "UTF-8");
try {
BitMatrix bitMatrix = new QRCodeWriter().encode(text, BarcodeFormat.QR_CODE, qrcodeWidth, qrcodeHeight, hints);
// 将像素点转成格子
int width = bitMatrix.getWidth();
int height = bitMatrix.getHeight();
for (int y = 30; y < height - 30; y += 10) {
for (int x = 30; x < width - 20; x += 10) {
boolean isBlack = bitMatrix.get(x, y);
System.out.print(isBlack ? " " : "\u001b[47m \u001b[0m");
}
System.out.println();
}
}
catch (WriterException e) {
e.printStackTrace();
}
}
示例4: createQRCode
import com.google.zxing.WriterException; //导入方法依赖的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;
}
示例5: generateQRCode
import com.google.zxing.WriterException; //导入方法依赖的package包/类
public Bitmap generateQRCode(String text) {
Bitmap bmp = null;
Hashtable<EncodeHintType, ErrorCorrectionLevel> hintMap = new Hashtable<EncodeHintType, ErrorCorrectionLevel>();
hintMap.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H); // H = 30% damage
int size = 256;
BitMatrix bitMatrix = null;
try {
bitMatrix = new QRCodeWriter().encode(text, BarcodeFormat.QR_CODE, size, size, hintMap);
int width = bitMatrix.getWidth();
bmp = Bitmap.createBitmap(width, width, Bitmap.Config.RGB_565);
for (int x = 0; x < width; x++) {
for (int y = 0; y < width; y++) {
bmp.setPixel(y, x, bitMatrix.get(x, y) == true ? Color.BLACK : Color.WHITE);
}
}
} catch (WriterException e) {
e.printStackTrace();
}
return bmp;
}
示例6: generate
import com.google.zxing.WriterException; //导入方法依赖的package包/类
public Bitmap generate(String text, int width, int height) {
Map<EncodeHintType, Object> hints = new HashMap<>();
hints.put(EncodeHintType.CHARACTER_SET, "utf-8");
hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.M);
try {
BitMatrix bitMatrix = new QRCodeWriter().encode(text, BarcodeFormat.QR_CODE, width, height, hints);
int[] pixels = new int[width * height];
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
if (bitMatrix.get(j, i)) {
pixels[i * width + j] = 0x00000000;
} else {
pixels[i * height + j] = 0xffffffff;
}
}
}
Bitmap bitmap = Bitmap.createBitmap(pixels, 0, width, width, height, Bitmap.Config.RGB_565);
bitmap = addLogo(bitmap);
return bitmap;
} catch (WriterException e) {
e.printStackTrace();
}
return null;
}
示例7: createImage
import com.google.zxing.WriterException; //导入方法依赖的package包/类
private void createImage(String text,int QR_WIDTH,int QR_HEIGHT) {
try {
// 需要引入core包
QRCodeWriter writer = new QRCodeWriter();
// 把输入的文本转为二维码
BitMatrix martix = writer.encode(text, BarcodeFormat.QR_CODE,
QR_WIDTH, QR_HEIGHT);
System.out.println("w:" + martix.getWidth() + "h:"
+ martix.getHeight());
Hashtable<EncodeHintType, Object> hints = new Hashtable<>();
hints.put(EncodeHintType.CHARACTER_SET, "utf-8");
hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
BitMatrix bitMatrix = new QRCodeWriter().encode(text,
BarcodeFormat.QR_CODE, QR_WIDTH, QR_HEIGHT, hints);
int[] pixels = new int[QR_WIDTH * QR_HEIGHT];
for (int y = 0; y < QR_HEIGHT; y++) {
for (int x = 0; x < QR_WIDTH; x++) {
if (bitMatrix.get(x, y)) {
pixels[y * QR_WIDTH + x] = 0xff000000;
} else {
pixels[y * QR_WIDTH + x] = 0xffffffff;
}
}
}
Bitmap bitmap = Bitmap.createBitmap(QR_WIDTH, QR_HEIGHT,
Bitmap.Config.ARGB_8888);
bitmap.setPixels(pixels, 0, QR_WIDTH, 0, 0, QR_WIDTH, QR_HEIGHT);
ivCode.setImageBitmap(bitmap);
} catch (WriterException e) {
e.printStackTrace();
}
}
示例8: init
import com.google.zxing.WriterException; //导入方法依赖的package包/类
private void init() {
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.k);
iamge1.setImageBitmap(EncodingHandler.createQRCode(url, 500, 500, bitmap));
try {
iamge2.setImageBitmap(EncodingHandler.createQRCode(url,500));
} catch (WriterException e) {
e.printStackTrace();
}
}
示例9: createQRCode
import com.google.zxing.WriterException; //导入方法依赖的package包/类
/**
* 创建二维码
*
* @param content content
* @param widthPix widthPix
* @param heightPix heightPix
* @param logoBm logoBm
* @return 二维码
*/
public static Bitmap createQRCode(String content, int widthPix, int heightPix, Bitmap logoBm) {
try {
if (content == null || "".equals(content)) {
return null;
}
// 配置参数
Map<EncodeHintType, Object> hints = new HashMap<>();
hints.put(EncodeHintType.CHARACTER_SET, "utf-8");
// 容错级别
hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
// 图像数据转换,使用了矩阵转换
BitMatrix bitMatrix = new QRCodeWriter().encode(content, BarcodeFormat.QR_CODE, widthPix, heightPix, hints);
int[] pixels = new int[widthPix * heightPix];
// 下面这里按照二维码的算法,逐个生成二维码的图片,
// 两个for循环是图片横列扫描的结果
for (int y = 0; y < heightPix; y++) {
for (int x = 0; x < widthPix; x++) {
if (bitMatrix.get(x, y)) {
pixels[y * widthPix + x] = 0xff000000;
} else {
pixels[y * widthPix + x] = 0xffffffff;
}
}
}
// 生成二维码图片的格式,使用ARGB_8888
Bitmap bitmap = Bitmap.createBitmap(widthPix, heightPix, Bitmap.Config.ARGB_8888);
bitmap.setPixels(pixels, 0, widthPix, 0, 0, widthPix, heightPix);
if (logoBm != null) {
bitmap = addLogo(bitmap, logoBm);
}
//必须使用compress方法将bitmap保存到文件中再进行读取。直接返回的bitmap是没有任何压缩的,内存消耗巨大!
return bitmap;
} catch (WriterException e) {
e.printStackTrace();
}
return null;
}
示例10: createQRCode
import com.google.zxing.WriterException; //导入方法依赖的package包/类
private Bitmap createQRCode() {
int QR_WIDTH = 100;
int QR_HEIGHT = 100;
try {
// 需要引入core包
QRCodeWriter writer = new QRCodeWriter();
String text = Util.getIMEI(this);
if (text == null || "".equals(text) || text.length() < 1) {
return null;
}
// 把输入的文本转为二维码
BitMatrix martix = writer.encode(text, BarcodeFormat.QR_CODE, QR_WIDTH, QR_HEIGHT);
System.out.println("w:" + martix.getWidth() + "h:" + martix.getHeight());
Hashtable<EncodeHintType, String> hints = new Hashtable<EncodeHintType, String>();
hints.put(EncodeHintType.CHARACTER_SET, "utf-8");
BitMatrix bitMatrix = new QRCodeWriter().encode(text, BarcodeFormat.QR_CODE, QR_WIDTH, QR_HEIGHT, hints);
int[] pixels = new int[QR_WIDTH * QR_HEIGHT];
for (int y = 0; y < QR_HEIGHT; y++) {
for (int x = 0; x < QR_WIDTH; x++) {
if (bitMatrix.get(x, y)) {
pixels[y * QR_WIDTH + x] = 0xff000000;
} else {
pixels[y * QR_WIDTH + x] = 0xffffffff;
}
}
}
// 生成的二维码
Bitmap bitmap = Bitmap.createBitmap(QR_WIDTH, QR_HEIGHT, Bitmap.Config.ARGB_8888);
bitmap.setPixels(pixels, 0, QR_WIDTH, 0, 0, QR_WIDTH, QR_HEIGHT);
return bitmap;
} catch (WriterException e) {
e.printStackTrace();
}
return null;
}
示例11: generateQRCode
import com.google.zxing.WriterException; //导入方法依赖的package包/类
/**
*
* @param amount
*/
public void generateQRCode(String amount) {
String coinName = getBaseActivity().getLastSyncedMessage().getCoinName();
String uriStr = coinName + ":" + _addr;
if (amount != null && !amount.isEmpty()) {
uriStr += "?amount="+amount;
}
try {
QRCodeWriter writer = new QRCodeWriter();
BitMatrix bitMatrix = writer.encode(uriStr, BarcodeFormat.QR_CODE, 512, 512);
int width = bitMatrix.getWidth();
int height = bitMatrix.getHeight();
Bitmap bmp = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);
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);
}
}
_receiveFragmentView.getQrImg().setImageBitmap(bmp);
} catch (WriterException e) {
e.printStackTrace();
}
}
示例12: createQRCode
import com.google.zxing.WriterException; //导入方法依赖的package包/类
/**
* 根据宽高生成二维码
*
* @param width
* @param height
* @param source
* @return
*/
public static Bitmap createQRCode(int width, int height, String source) {
try {
if (TextUtils.isEmpty(source)) {
return null;
}
Hashtable<EncodeHintType, String> hints = new Hashtable<>();
hints.put(EncodeHintType.CHARACTER_SET, "utf-8");
BitMatrix bitMatrix = new QRCodeWriter().encode(source, BarcodeFormat.QR_CODE, width, height, hints);
int[] pixels = new int[width * height];
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
if (bitMatrix.get(x, y)) {
pixels[y * width + x] = 0xff000000;
} else {
pixels[y * width + x] = 0xffffffff;
}
}
}
// sheng chen de er wei ma
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;
}
示例13: createQRCodeWithLogo3
import com.google.zxing.WriterException; //导入方法依赖的package包/类
/**
* bitmap作为底色
*
* @param text
* @param size
* @param mBitmap
* @return
*/
public static Bitmap createQRCodeWithLogo3(String text, int size, Bitmap mBitmap) {
try {
IMAGE_HALFWIDTH = size / 10;
Hashtable<EncodeHintType, Object> hints = new Hashtable<>();
hints.put(EncodeHintType.CHARACTER_SET, "utf-8");
hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
BitMatrix bitMatrix = new QRCodeWriter().encode(text,
BarcodeFormat.QR_CODE, size, size, hints);
//将logo图片按martix设置的信息缩放
mBitmap = Bitmap.createScaledBitmap(mBitmap, size, size, false);
int[] pixels = new int[size * size];
int color = 0xfff92736;
for (int y = 0; y < size; y++) {
for (int x = 0; x < size; x++) {
if (bitMatrix.get(x, y)) {
pixels[y * size + x] = color;
} else {
pixels[y * size + x] = mBitmap.getPixel(x, y) & 0x66ffffff;
}
}
}
Bitmap bitmap = Bitmap.createBitmap(size, size,
Bitmap.Config.ARGB_8888);
bitmap.setPixels(pixels, 0, size, 0, 0, size, size);
return bitmap;
} catch (WriterException e) {
e.printStackTrace();
return null;
}
}
示例14: createQRCodeWithLogo5
import com.google.zxing.WriterException; //导入方法依赖的package包/类
/**
* 生成带logo的二维码
* @param text
* @param size
* @param mBitmap
* @return
*/
public static Bitmap createQRCodeWithLogo5(String text, int size, Bitmap mBitmap) {
try {
IMAGE_HALFWIDTH = size / 10;
Hashtable<EncodeHintType, Object> hints = new Hashtable<>();
hints.put(EncodeHintType.CHARACTER_SET, "utf-8");
hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
BitMatrix bitMatrix = new QRCodeWriter().encode(text,
BarcodeFormat.QR_CODE, size, size, hints);
//将logo图片按martix设置的信息缩放
mBitmap = Bitmap.createScaledBitmap(mBitmap, size, size, false);
int width = bitMatrix.getWidth();//矩阵高度
int height = bitMatrix.getHeight();//矩阵宽度
int halfW = width / 2;
int halfH = height / 2;
Matrix m = new Matrix();
float sx = (float) 2 * IMAGE_HALFWIDTH / mBitmap.getWidth();
float sy = (float) 2 * IMAGE_HALFWIDTH
/ mBitmap.getHeight();
m.setScale(sx, sy);
//设置缩放信息
//将logo图片按martix设置的信息缩放
mBitmap = Bitmap.createBitmap(mBitmap, 0, 0,
mBitmap.getWidth(), mBitmap.getHeight(), m, false);
int[] pixels = new int[size * size];
for (int y = 0; y < size; y++) {
for (int x = 0; x < size; x++) {
if (x > halfW - IMAGE_HALFWIDTH && x < halfW + IMAGE_HALFWIDTH
&& y > halfH - IMAGE_HALFWIDTH
&& y < halfH + IMAGE_HALFWIDTH) {
//该位置用于存放图片信息
//记录图片每个像素信息
pixels[y * width + x] = mBitmap.getPixel(x - halfW
+ IMAGE_HALFWIDTH, y - halfH + IMAGE_HALFWIDTH);
} else {
if (bitMatrix.get(x, y)) {
pixels[y * size + x] = 0xff37b19e;
} else {
pixels[y * size + x] = 0xffffffff;
}
}
}
}
Bitmap bitmap = Bitmap.createBitmap(size, size,
Bitmap.Config.ARGB_8888);
bitmap.setPixels(pixels, 0, size, 0, 0, size, size);
return bitmap;
} catch (WriterException e) {
e.printStackTrace();
return null;
}
}
示例15: createQRCodeWithLogo6
import com.google.zxing.WriterException; //导入方法依赖的package包/类
/**
* 修改三个顶角颜色的,带logo的二维码
* @param text
* @param size
* @param mBitmap
* @return
*/
public static Bitmap createQRCodeWithLogo6(String text, int size, Bitmap mBitmap) {
try {
IMAGE_HALFWIDTH = size / 10;
Hashtable<EncodeHintType, Object> hints = new Hashtable<>();
hints.put(EncodeHintType.CHARACTER_SET, "utf-8");
/*
* 设置容错级别,默认为ErrorCorrectionLevel.L
* 因为中间加入logo所以建议你把容错级别调至H,否则可能会出现识别不了
*/
hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
BitMatrix bitMatrix = new QRCodeWriter().encode(text,
BarcodeFormat.QR_CODE, size, size, hints);
//将logo图片按martix设置的信息缩放
mBitmap = Bitmap.createScaledBitmap(mBitmap, size, size, false);
int width = bitMatrix.getWidth();//矩阵高度
int height = bitMatrix.getHeight();//矩阵宽度
int halfW = width / 2;
int halfH = height / 2;
Matrix m = new Matrix();
float sx = (float) 2 * IMAGE_HALFWIDTH / mBitmap.getWidth();
float sy = (float) 2 * IMAGE_HALFWIDTH
/ mBitmap.getHeight();
m.setScale(sx, sy);
//设置缩放信息
//将logo图片按martix设置的信息缩放
mBitmap = Bitmap.createBitmap(mBitmap, 0, 0,
mBitmap.getWidth(), mBitmap.getHeight(), m, false);
int[] pixels = new int[size * size];
for (int y = 0; y < size; y++) {
for (int x = 0; x < size; x++) {
if (x > halfW - IMAGE_HALFWIDTH && x < halfW + IMAGE_HALFWIDTH
&& y > halfH - IMAGE_HALFWIDTH
&& y < halfH + IMAGE_HALFWIDTH) {
//该位置用于存放图片信息
//记录图片每个像素信息
pixels[y * width + x] = mBitmap.getPixel(x - halfW
+ IMAGE_HALFWIDTH, y - halfH + IMAGE_HALFWIDTH);
} else {
if (bitMatrix.get(x, y)) {
pixels[y * size + x] = 0xff111111;
if(x<115&&(y<115||y>=size-115)||(y<115&&x>=size-115)){
pixels[y * size + x] = 0xfff92736;
}
} else {
pixels[y * size + x] = 0xffffffff;
}
}
}
}
Bitmap bitmap = Bitmap.createBitmap(size, size,
Bitmap.Config.ARGB_8888);
bitmap.setPixels(pixels, 0, size, 0, 0, size, size);
return bitmap;
} catch (WriterException e) {
e.printStackTrace();
return null;
}
}