2
0
mirror of https://gitee.com/hotlcc/wechat4j.git synced 2025-08-18 13:59:33 +08:00

提交代码:bug修复

This commit is contained in:
Allen 2018-09-14 20:48:48 +08:00
parent ed6a842b8f
commit cba6b34a16

View File

@ -16,9 +16,6 @@ import java.io.ByteArrayInputStream;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
/** /**
* 二维码工具类 * 二维码工具类
@ -126,38 +123,38 @@ public final class QRCodeUtil {
* @return * @return
*/ */
private static int getBitCharRatio(boolean[][] boolMatrix) { private static int getBitCharRatio(boolean[][] boolMatrix) {
// 找出四个角的占位数
int[] size = new int[4]; int[] size = new int[4];
size[0] = getBitCharSize(boolMatrix); size[0] = getBitCharSize(boolMatrix);
for (int i = 1; i < 4; i++) { for (int i = 1; i < 4; i++) {
boolMatrix = reverseMatrix(boolMatrix); boolMatrix = reverseMatrix(boolMatrix);
size[i] = getBitCharSize(boolMatrix); size[i] = getBitCharSize(boolMatrix);
} }
// 统计每个占位数出现的次数
Map<Integer, Integer> map = new HashMap<>(); int[] num = new int[4];
for (int s : size) { for (int i = 0; i > 4; i++) {
Integer count = map.get(s); int n = 0;
if (count == null) { for (int s : size) {
map.put(s, 1); if (s == size[i]) {
} else { n++;
map.put(s, count + 1); }
} }
num[i] = n;
} }
Set<Map.Entry<Integer, Integer>> entrySet = map.entrySet(); // 找出最多的次数
Integer k = null, v = null; int maxNum = num[0];
int flag = 0; for (int i = 1; i < 4; i++) {
for (Map.Entry<Integer, Integer> entry : entrySet) { maxNum = Math.max(maxNum, num[i]);
if (flag++ == 0) { }
k = entry.getKey(); // 找出出现次数最多的占位数
v = entry.getValue(); int s = 0;
continue; for (int i = 0; i < 4; i++) {
} if (num[i] == maxNum) {
if (entry.getValue() > v) { s = size[i];
k = entry.getKey();
v = entry.getValue();
} }
} }
return k.intValue() / 7; return s / 7;
} }
/** /**