Browse Source

改照片了

menglu 3 years ago
parent
commit
4e26f1fbc6

+ 1 - 1
ibms-data-sdk/src/main/java/a/A.java

@@ -41,7 +41,7 @@ public class A {
 			InputStream is = new FileInputStream(choose);
 			BufferedImage bi = ImageIO.read(is);
 			is.close();
-			List<String> strList = ImageUtil.toStringList(bi);
+			List<String> strList = ImageUtil.toStringList(bi, true);
 			for (String str : strList) {
 				System.out.println(str);
 				// log.error(str);

+ 8 - 9
ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/util/ImageUtil.java

@@ -164,6 +164,11 @@ public class ImageUtil {
 	}
 
 	public static List<String> toStringList(BufferedImage bi) {
+		List<String> result = toStringList(bi, false);
+		return result;
+	}
+
+	public static List<String> toStringList(BufferedImage bi, boolean reverse) {
 		List<String> result = new ArrayList<String>();
 		int width = bi.getWidth();
 		int height = bi.getHeight();
@@ -191,17 +196,11 @@ public class ImageUtil {
 					totalValue += value;
 				}
 				int charIndex = (int) (1.0 * totalValue / total_rgb * base.length());
+				if (reverse) {
+					charIndex = base.length() - 1 - charIndex;
+				}
 				char ch = base.charAt(charIndex);
 				sb.append(ch);
-				// String str;
-				// if (totalValue < 256) {
-				// str = "█";
-				// } else if (totalValue < 768) {
-				// str = "▓";
-				// } else {
-				// str = " ";
-				// }
-				// sb.append(str);
 			}
 			result.add(sb.toString());
 		}