From fe113ca87d43ee7b2f8e9cf84a285fa650f99e6f Mon Sep 17 00:00:00 2001 From: Namophice Date: Sun, 2 Jul 2023 16:34:04 +0800 Subject: [PATCH] =?UTF-8?q?=E7=81=B0=E5=BA=A6=E8=BD=AC=E6=8D=A2=E9=80=BB?= =?UTF-8?q?=E8=BE=91=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../inkphotoalbum/business/MasterService.java | 25 ------------------- .../inkphotoalbum/config/DefaultConfig.java | 3 +-- .../inkphotoalbum/utils/ImageUtil.java | 15 +++++++---- 3 files changed, 11 insertions(+), 32 deletions(-) diff --git a/src/main/java/icu/namophice/inkphotoalbum/business/MasterService.java b/src/main/java/icu/namophice/inkphotoalbum/business/MasterService.java index f17bf1b..667caf5 100644 --- a/src/main/java/icu/namophice/inkphotoalbum/business/MasterService.java +++ b/src/main/java/icu/namophice/inkphotoalbum/business/MasterService.java @@ -7,7 +7,6 @@ import icu.namophice.inkphotoalbum.utils.ImageUtil; import java.awt.image.BufferedImage; import java.io.File; -import java.security.cert.X509Certificate; import java.util.Arrays; import java.util.Random; @@ -90,28 +89,4 @@ public class MasterService { } } - /** - * 跳过SSL证书验证 - * @throws Exception - */ - private static void trustAllHttpsCertificates() throws Exception { - javax.net.ssl.TrustManager[] trustAllCerts = new javax.net.ssl.TrustManager[1]; - javax.net.ssl.TrustManager tm = new miTM(); - trustAllCerts[0] = tm; - javax.net.ssl.SSLContext sc = javax.net.ssl.SSLContext.getInstance("SSL"); - sc.init(null, trustAllCerts, null); - javax.net.ssl.HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); - } - - private static class miTM implements javax.net.ssl.TrustManager, javax.net.ssl.X509TrustManager { - @Override - public void checkClientTrusted(X509Certificate[] chain, String authType) {} - @Override - public void checkServerTrusted(X509Certificate[] chain, String authType) {} - @Override - public X509Certificate[] getAcceptedIssuers() { - return null; - } - } - } diff --git a/src/main/java/icu/namophice/inkphotoalbum/config/DefaultConfig.java b/src/main/java/icu/namophice/inkphotoalbum/config/DefaultConfig.java index c60cfc5..dec5416 100644 --- a/src/main/java/icu/namophice/inkphotoalbum/config/DefaultConfig.java +++ b/src/main/java/icu/namophice/inkphotoalbum/config/DefaultConfig.java @@ -17,8 +17,7 @@ public class DefaultConfig { "https://www.dmoe.cc/random.php", "https://cdn.seovx.com/d/?mom=302", "https://api.paugram.com/wallpaper/", - "https://api.yimian.xyz/img", - "https://img.xjh.me/random_img.php" + "https://api.yimian.xyz/img" }; public static final String configFileName = "conf.json"; diff --git a/src/main/java/icu/namophice/inkphotoalbum/utils/ImageUtil.java b/src/main/java/icu/namophice/inkphotoalbum/utils/ImageUtil.java index 0eda984..9b8cdfc 100644 --- a/src/main/java/icu/namophice/inkphotoalbum/utils/ImageUtil.java +++ b/src/main/java/icu/namophice/inkphotoalbum/utils/ImageUtil.java @@ -317,6 +317,7 @@ public class ImageUtil { final int height = originImage.getHeight(); BufferedImage targetImage = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_GRAY); + final int maxValue = 0xf73140, minValue = 0x83fd10; for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { int rgb = originImage.getRGB(i, j); @@ -325,14 +326,18 @@ public class ImageUtil { int binValue; // 0是黑 1是白 ,或者说数值小就靠近黑色,数值大就靠近白色 - if(oneGate > 0xec82e0) { // 大于一定数值,直接用白点 + if (oneGate > maxValue) { // 大于一定数值,直接用白点 binValue = 0xffffff; - } else if(oneGate < 0x6ea050) { // 小于一定数值直接用黑点 + } else if (oneGate < minValue) { // 小于一定数值直接用黑点 binValue = 0; - } else if(oneGate > randomNum) { // 模拟灰阶使用随机数画白点 - binValue = 0xffffff; } else { - binValue = 0; + // 模拟灰阶使用随机数画白点 + final int random = new Random().nextInt(100); + if (oneGate > ((maxValue - minValue) / 2) + minValue) { + binValue = random < 60 ? 0xffffff : 0; + } else { + binValue = random < 80 ? 0 : 0xffffff; + } } targetImage.setRGB(i, j, binValue); }