当前位置: 代码迷 >> 综合 >> zxing 黑屏 无法显示图像问题 及中文乱码问题解决
  详细解决方案

zxing 黑屏 无法显示图像问题 及中文乱码问题解决

热度:14   发布时间:2023-12-22 09:00:25.0

修改zxing/camera/CameraConfigurationManager.java文件此函数findBestPreviewSizeValue()为:

private static Point findBestPreviewSizeValue(CharSequence previewSizeValueString, Point screenResolution) {int bestX = 0;int bestY = 0;int diff = Integer.MAX_VALUE;int maybeOKX = 0;int maybeOKY = 0;float maybeOKScale = -1;for (String previewSize : COMMA_PATTERN.split(previewSizeValueString)) {Print.d(TAG, "previewSize = " + previewSize);previewSize = previewSize.trim();int dimPosition = previewSize.indexOf('x');if (dimPosition < 0) {Log.w(TAG, "Bad preview-size: " + previewSize);continue;}int newX;int newY;try {newX = Integer.parseInt(previewSize.substring(0, dimPosition));newY = Integer.parseInt(previewSize.substring(dimPosition + 1));} catch (NumberFormatException nfe) {Log.w(TAG, "Bad preview-size: " + previewSize);continue;}int newDiff = Math.abs(newX - screenResolution.x) + Math.abs(newY - screenResolution.y);boolean isScaleRight = ((double)newX / (double)screenResolution.y == (double)newY / (double)screenResolution.x);Log.d(TAG, isScaleRight + "##" + newX + " / " + screenResolution.y + " == " + newY + " / " + screenResolution.x);if (newDiff == 0) {bestX = newX;bestY = newY;break;} else if (isScaleRight && newDiff < diff) {bestX = newX;bestY = newY;diff = newDiff;} else {float scale = Math.abs((float)((float)newX / (float)newY) - ((float)screenResolution.x - (float)screenResolution.y));if (maybeOKScale == -1 || scale < maybeOKScale) {maybeOKX = newX;maybeOKY = newY;maybeOKScale = scale;}}}if (bestX > 0 && bestY > 0) {return new Point(bestX, bestY);}Print.e(TAG, "return maybeOK....x = " + maybeOKX + ", y = " + maybeOKY);//640x480,1024x768return new Point(maybeOKX, maybeOKY);
//    return null;}


zxing生成二维码的中文乱码问题原因不详,解决方法:

修改core目录下的com.google.zxing.qrcode.encoder.Encoder.java文件,static final String DEFAULT_BYTE_MODE_ENCODING = "ISO8859-1";修改为UTF-8

然后重新打个zxingcore源码的jar包,直接在eclipse的export中就可以导出jar包了

网上有些讲解此类问题的文章,具体谷歌“zxing   utf8   chinese”

  相关解决方案