Skip to content

Commit 6be6279

Browse files
committed
feat: 边框判断优化
1 parent 670de7a commit 6be6279

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

plugins/image-plugin/src/main/java/com/github/hui/quick/plugin/image/wrapper/pixel/model/PixelStyleEnum.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,17 @@ public void render(Graphics2D g2d, BufferedImage source, ImgPixelOptions options
120120
g2d.setFont(options.getFont());
121121
}
122122

123-
if (options.getBgPredicate().test(source.getRGB(x, y))) {
123+
int blockSize = options.getBlockSize();
124+
int[] colors = ImgPixelHelper.getPixels(source, x, y, blockSize, blockSize);
125+
boolean allBg = true;
126+
for (int i = 0; i < colors.length; i++) {
127+
if (!options.getBgPredicate().test(colors[i])) {
128+
// 这个区域内全部都是背景时,才表示为背景图
129+
allBg = false;
130+
break;
131+
}
132+
}
133+
if (allBg) {
124134
// 背景,直接跳过
125135
PixelContextHolder.addChar(y, options.getBgChar());
126136
return;

plugins/image-plugin/src/test/java/com/github/hui/quick/plugin/test/pixel/Icon2PixelTest.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@
2020
*/
2121
public class Icon2PixelTest {
2222

23-
public static List<String> toStr(String path, String file) {
24-
int blockSize = 6;
23+
public static List<String> toStr(String path, String file, int blockSize) {
2524
while (true) {
2625
if (!path.endsWith("/")) path += "/";
2726
String img = path + file;
@@ -141,12 +140,16 @@ private static void saveToFile(String path, String file, List<String> s) throws
141140
public void testBorderOut() throws Exception {
142141
String absPath = "d://quick-media/pixel-in/";
143142
String in = "day";
143+
// icon 对应的是6
144+
int blockSize = 6;
145+
// 复杂图,对应大一点
146+
blockSize = 26;
144147
File file = new File(absPath + in);
145148
int index = 1;
146149
for (File f : file.listFiles()) {
147150
String fName = f.getName();
148151
System.out.println(">>>>>>" + fName);
149-
List<String> s = toStr(absPath + in, fName);
152+
List<String> s = toStr(absPath + in, fName, blockSize);
150153
preview(s);
151154
saveToFile(absPath + "out", "lvl" + index, s);
152155
index += 1;

0 commit comments

Comments
 (0)