2
0
mirror of https://gitee.com/hotlcc/wechat4j.git synced 2025-06-09 12:04:05 +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 i = 0; i > 4; i++) {
int n = 0;
for (int s : size) { for (int s : size) {
Integer count = map.get(s); if (s == size[i]) {
if (count == null) { n++;
map.put(s, 1);
} else {
map.put(s, count + 1);
} }
} }
Set<Map.Entry<Integer, Integer>> entrySet = map.entrySet(); num[i] = n;
Integer k = null, v = null;
int flag = 0;
for (Map.Entry<Integer, Integer> entry : entrySet) {
if (flag++ == 0) {
k = entry.getKey();
v = entry.getValue();
continue;
} }
if (entry.getValue() > v) { // 找出最多的次数
k = entry.getKey(); int maxNum = num[0];
v = entry.getValue(); for (int i = 1; i < 4; i++) {
maxNum = Math.max(maxNum, num[i]);
}
// 找出出现次数最多的占位数
int s = 0;
for (int i = 0; i < 4; i++) {
if (num[i] == maxNum) {
s = size[i];
} }
} }
return k.intValue() / 7; return s / 7;
} }
/** /**