点阵图生成器

本文最后更新于:2024年9月12日 晚上

点阵图生成器

该点阵图生成器,能将图片转换为等大小的点阵图。

效果

  • 正常输出

    ⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⣀⣀⣤⣤⣤⣤⣤⣀⣀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀
    ⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⣀⣴⠾⠛⠋⠉⠁⢀⢀⢀⢀⠉⠉⠛⠳⢦⣄⡀⣀⣀⣀⣀⢀⢀⢀⢀⢀⢀
    ⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⣤⠾⠋⢀⢀⢀⢀⢀⢀⢀⢀⡀⢀⢀⢀⢀⣀⡀⠉⠻⣏⠉⠉⠙⠻⢦⡀⢀⢀⢀
    ⢀⢀⢀⢀⢀⢀⢀⢀⣠⡾⠃⢀⢀⢀⢀⢀⢀⢀⢀⢀⡏⠉⣆⢀⢀⠘⡇⠈⣆⢀⠈⠳⣄⢀⢀⠈⣷⢀⢀⢀
    ⢀⢀⢀⢀⢀⢀⢀⣰⠏⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⣧⣀⣸⡄⢀⢀⢷⣤⣿⡄⢀⢀⠙⣆⢀⢠⡿⢀⢀⢀
    ⢀⢀⢀⢀⢀⢀⢰⣏⡤⠖⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢹⣿⣿⡇⢀⢀⠘⣿⣿⡇⢀⢀⡀⠸⣆⣾⠃⢀⢀⢀
    ⢀⢀⢀⢀⢀⣴⠟⠁⢀⢀⢀⢀⢀⢀⢀⢀⢀⣠⣤⣀⠈⢿⣿⡇⢀⢀⢀⠙⠿⠃⠐⠿⠛⢀⢻⡇⢀⢀⢀⢀
    ⢀⢀⢀⢀⣾⠃⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⠈⠙⠛⠋⢀⢀⢀⢀⠘⠒⠚⠁⢀⢀⢀⢀⢀⢀⢸⡇⢀⢀⢀⢀
    ⢀⢀⢀⣸⡇⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⣀⣤⣤⣤⣤⣤⣀⢀⢀⢀⢀⢀⢀⢀⢀⢸⡇⢀⢀⢀⢀
    ⢀⢀⢀⢹⣇⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⣤⣾⣻⣏⣀⣤⣾⣾⣿⣿⣷⢀⢀⢀⢀⢀⢀⢀⣾⠃⢀⢀⢀⢀
    ⢀⢀⢀⢀⠻⢦⣄⣀⣀⣀⣀⣤⡴⢆⣴⣿⣷⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⢀⢀⢀⢀⢀⣰⡟⢀⢀⢀⢀⢀
    ⢀⢀⢀⢀⢀⢀⠈⠹⣯⠉⠁⢀⢠⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠁⢀⢀⢀⢀⣰⡟⢀⢀⢀⢀⢀⢀
    ⢀⢀⢀⢀⢀⢀⢀⢀⠘⢷⣄⢀⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡏⢀⢀⢀⢀⣼⠋⢀⢀⢀⢀⢀⢀⢀
    ⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⠙⢷⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡟⢀⢀⣠⣶⣿⠁⢀⢀⢀⢀⢀⢀⢀⢀
    ⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣯⣴⣶⣿⣿⣿⠃⢀⢀⢀⢀⢀⢀⢀⢀⢀
    ⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⠻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠃⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀
    ⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⠉⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡟⠁⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀
    ⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⠘⣿⣿⣿⣿⡏⢁⣠⣿⠟⠋⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀
    ⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⠈⠻⠿⠿⠿⠟⠋⠁⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀
  • 反转输出

    ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠿⠿⠛⠛⠛⠛⠛⠿⠿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
    ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠿⠋⣁⣤⣴⣶⣾⣿⣿⣿⣿⣶⣶⣤⣌⡙⠻⢿⠿⠿⠿⠿⣿⣿⣿⣿⣿⣿
    ⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠛⣁⣴⣿⣿⣿⣿⣿⣿⣿⡿⢿⣿⣿⣿⣿⠿⢿⣶⣄⠰⣶⣶⣦⣄⡙⢿⣿⣿⣿
    ⣿⣿⣿⣿⣿⣿⣿⣿⠟⢁⣼⣿⣿⣿⣿⣿⣿⣿⣿⣿⢰⣶⠹⣿⣿⣧⢸⣷⠹⣿⣷⣌⠻⣿⣿⣷⠈⣿⣿⣿
    ⣿⣿⣿⣿⣿⣿⣿⠏⣰⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠘⠿⠇⢻⣿⣿⡈⠛⢀⢻⣿⣿⣦⠹⣿⡟⢀⣿⣿⣿
    ⣿⣿⣿⣿⣿⣿⡏⠰⢛⣩⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡆⢀⢀⢸⣿⣿⣧⢀⢀⢸⣿⣿⢿⣇⠹⠁⣼⣿⣿⣿
    ⣿⣿⣿⣿⡿⠋⣠⣾⣿⣿⣿⣿⣿⣿⣿⣿⡿⠟⠛⠿⣷⡀⢀⢸⣿⣿⣿⣦⣀⣼⣯⣀⣤⣿⡄⢸⣿⣿⣿⣿
    ⣿⣿⣿⡿⠁⣼⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣦⣤⣴⣿⣿⣿⣿⣧⣭⣥⣾⣿⣿⣿⣿⣿⣿⡇⢸⣿⣿⣿⣿
    ⣿⣿⣿⠇⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠿⠛⠛⠛⠛⠛⠿⣿⣿⣿⣿⣿⣿⣿⣿⡇⢸⣿⣿⣿⣿
    ⣿⣿⣿⡆⠸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠛⠁⠄⠰⠿⠛⠁⠁⢀⢀⠈⣿⣿⣿⣿⣿⣿⣿⠁⣼⣿⣿⣿⣿
    ⣿⣿⣿⣿⣄⡙⠻⠿⠿⠿⠿⠛⢋⡹⠋⢀⠈⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢸⣿⣿⣿⣿⣿⠏⢠⣿⣿⣿⣿⣿
    ⣿⣿⣿⣿⣿⣿⣷⣆⠐⣶⣾⣿⡟⠁⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⣾⣿⣿⣿⣿⠏⢠⣿⣿⣿⣿⣿⣿
    ⣿⣿⣿⣿⣿⣿⣿⣿⣧⡈⠻⣿⠁⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢰⣿⣿⣿⡿⠃⣴⣿⣿⣿⣿⣿⣿⣿
    ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⡈⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢠⣿⡿⠟⠉⢀⣾⣿⣿⣿⣿⣿⣿⣿⣿
    ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡄⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⠐⠋⠉⢀⢀⢀⣼⣿⣿⣿⣿⣿⣿⣿⣿⣿
    ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣄⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⣼⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
    ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣶⡄⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢠⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
    ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣧⢀⢀⢀⢀⢰⡾⠟⢀⣠⣴⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
    ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣄⣀⣀⣀⣠⣴⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿

使用方式

  1. 将图片进行预处理

    首先进行去色处理(这一步是为了方便观察),之后调整图片大小(以宽度不超过 104 像素为宜)

    之后进一步使用加深、减淡工具进行调整,并以阈值工具查看最终效果

    最终导出预处理后的图片

  2. 生成点阵图对象

    调用 Pic Pic.create(String path) 方法(Pic 类的静态方法),传入图片路径。该方法的返回值即点阵图对象。

    或者也能直接使用构造器,new Pic(File path),传入图片文件 file,即可构造点阵图对象

  3. 获取字符串

    使用点阵图对象的 toString() 方法可得到点阵图字符串。

静态方法说明

  1. 生成点阵图static Pic create(String path, boolean anti)

    用途:根据图片路径,生成该图片的对应点阵图

    参数:path 为图片路径;anti 为 true 时生成反向点阵图,默认为 false

    返回值:点阵图封装类对象 Pic pic。调用其 toString() 方法即可输出点阵图字符串。

    也能使用构造器构造点阵图对象:Pic(File path, boolean anti)

  2. 点阵图反转static String reverse(String picture)

    用途:生成传入点阵图的反转点阵图,图中所有黑点与空点互换。使用默认空格时,可能造成观感下降。请尽可能在第一次生成时选择生成反向点阵图,而非使用该方法将点阵图反转。

    参数:picture 为点阵图字符串

    返回值:字符串(内容为反向点阵图)

  3. 点阵图安全化static String toSafe(String picutre)

    用途:生成传入点阵图的安全点阵图。安全点阵图是以 字符代替原有空格的点阵图

    参数:picture 为点阵图字符串

    返回值:字符串(内容为安全点阵图)

  4. 点阵图一般化static String toNormal(String picture)

    用途:生成传入点阵图的一般化版本。一般化版本是以一个盲文字符空格代替原有空格的点阵图。在多数字体中,盲文空格与盲文字符宽度不一。因此此举将造成点阵图竖列无法对齐的问题。但在一些字体下效果比原始方案好

    参数:picture 为点阵图字符串

    返回值:字符串(内容为一般化点阵图)

  5. 自定义点阵图安全化static String toSafe_D(String picutre, char replace)

    用途:生成传入点阵图的安全点阵图。该安全点阵图以传入的 字符/字符串 代替原有空格。

    参数:picture 为点阵图字符串;replace 替换后的 字符/字符串,可以传入一个 charString

    返回值:字符串(内容为安全点阵图)

  6. 设置默认空格static String changeDefaultSpace(char... spaces)

    用途:设置点阵图中空格的样式。也有 changeDefaultSpace(String spaces) 的方法

    参数:spaces 为空格字符串

    返回值:之前的空格字符串。特别地,如果传入空参,默认空格设置将被复原为最初的设置

特别说明

  1. 在不同字体下,同一字符的宽度可能不同。这会造成点阵图无法对齐,从而使观感下降。一般来讲,盲文字符间宽度一致,但与空格字符宽度不一致。

    本生成器为了规避该问题,将默认的空格字符替换为盲文的 字符。虽然能够对齐,但观感有所下降。

  2. 本生成器中给出了一些不同宽度的空格。用户将其自行组合后,就能特定字体下实现完美的对齐效果。

    点阵图的构造器 Pic(String pic, String space) 可以在构造时设置空格。

    也能使用 Pic changeSpace(String space) 方法来修改点阵图的空格。

  3. 本点阵图对象的多数方法支持链式调用。包括:

    toSafe()toSafe_D(char... replace)toNormal()reverse()changeSpace(char... spaces)reCreate(File path)

    只是要注意,调用后返回的是新的对象,原对象的内容不会发生改变。

    要想实现对原对象的链式修改,只需在开始时先执行 changeable()

Java 代码(version 0.18)

class Pic {
    public static final char SPACE = ' ';
    public static final char SPACE_6PE = '\u2006';
    public static final char SPACE_THIN = '\u2009';
    public static final char SPACE_BRAILLE = '\u2800';
    public static final char SPACE_HAIR = '\u200a';
    public static final char SINGLE_BULL_00 = '⠁';
    public static final char SINGLE_BULL_01 = '⠈';
    public static final char SINGLE_BULL_10 = '⠂';
    public static final char SINGLE_BULL_11 = '⠐';
    public static final char SINGLE_BULL_20 = '⠄';
    public static final char SINGLE_BULL_21 = '⠠';
    public static final char SINGLE_BULL_30 = '⡀';
    public static final char SINGLE_BULL_31 = '⢀';
    public static final char FULL_BULL = '⣿';
    /* ↑ 定义部分字符以便用户调用 ↑ */

    private static final char[] C;
    private static final Map<Character, Character> RC = new HashMap<>();
    private static final char TEMP_CHAR = '\u0000';
    private static final String O_D_SPACE = String.valueOf(new char[]{SINGLE_BULL_20});
    private static String default_space = O_D_SPACE;

    static {
        C = new char[]{
                TEMP_CHAR, '⠁', '⠂', '⠃', '⠄', '⠅', '⠆', '⠇', '⠈', '⠉', '⠊', '⠋', '⠌', '⠍', '⠎', '⠏',
                '⠐', '⠑', '⠒', '⠓', '⠔', '⠕', '⠖', '⠗', '⠘', '⠙', '⠚', '⠛', '⠜', '⠝', '⠞', '⠟',
                '⠠', '⠡', '⠢', '⠣', '⠤', '⠥', '⠦', '⠧', '⠨', '⠩', '⠪', '⠫', '⠬', '⠭', '⠮', '⠯',
                '⠰', '⠱', '⠲', '⠳', '⠴', '⠵', '⠶', '⠷', '⠸', '⠹', '⠺', '⠻', '⠼', '⠽', '⠾', '⠿',
                '⡀', '⡁', '⡂', '⡃', '⡄', '⡅', '⡆', '⡇', '⡈', '⡉', '⡊', '⡋', '⡌', '⡍', '⡎', '⡏',
                '⡐', '⡑', '⡒', '⡓', '⡔', '⡕', '⡖', '⡗', '⡘', '⡙', '⡚', '⡛', '⡜', '⡝', '⡞', '⡟',
                '⡠', '⡡', '⡢', '⡣', '⡤', '⡥', '⡦', '⡧', '⡨', '⡩', '⡪', '⡫', '⡬', '⡭', '⡮', '⡯',
                '⡰', '⡱', '⡲', '⡳', '⡴', '⡵', '⡶', '⡷', '⡸', '⡹', '⡺', '⡻', '⡼', '⡽', '⡾', '⡿',
                '⢀', '⢁', '⢂', '⢃', '⢄', '⢅', '⢆', '⢇', '⢈', '⢉', '⢊', '⢋', '⢌', '⢍', '⢎', '⢏',
                '⢐', '⢑', '⢒', '⢓', '⢔', '⢕', '⢖', '⢗', '⢘', '⢙', '⢚', '⢛', '⢜', '⢝', '⢞', '⢟',
                '⢠', '⢡', '⢢', '⢣', '⢤', '⢥', '⢦', '⢧', '⢨', '⢩', '⢪', '⢫', '⢬', '⢭', '⢮', '⢯',
                '⢰', '⢱', '⢲', '⢳', '⢴', '⢵', '⢶', '⢷', '⢸', '⢹', '⢺', '⢻', '⢼', '⢽', '⢾', '⢿',
                '⣀', '⣁', '⣂', '⣃', '⣄', '⣅', '⣆', '⣇', '⣈', '⣉', '⣊', '⣋', '⣌', '⣍', '⣎', '⣏',
                '⣐', '⣑', '⣒', '⣓', '⣔', '⣕', '⣖', '⣗', '⣘', '⣙', '⣚', '⣛', '⣜', '⣝', '⣞', '⣟',
                '⣠', '⣡', '⣢', '⣣', '⣤', '⣥', '⣦', '⣧', '⣨', '⣩', '⣪', '⣫', '⣬', '⣭', '⣮', '⣯',
                '⣰', '⣱', '⣲', '⣳', '⣴', '⣵', '⣶', '⣷', '⣸', '⣹', '⣺', '⣻', '⣼', '⣽', '⣾', '⣿'
        };
        for (int i = 0; i < C.length; i++) RC.put(C[i], C[0b11111111 ^ i]);
        RC.put('\n', '\n');
    }

    public static String getDefaultSpace() {
        return Pic.default_space;
    }

    public static Pic create(String path) {
        return create(path, false, Pic.default_space);
    }

    public static Pic create(String path, String space) {
        return create(path, false, space);
    }

    public static Pic create(String path, boolean anti) {
        return create(path, anti, Pic.default_space);
    }

    public static Pic create(String path, boolean anti, String space) {
        File file = new File(path);
        if (space == null || space.length() == 0) return create(file, anti, Pic.default_space);
        return create(file, anti, space);
    }

    public static Pic create(File path) {
        return create(path, false, Pic.default_space);
    }

    public static Pic create(File path, String space) {
        return create(path, false, space);
    }

    public static Pic create(File path, boolean anti) {
        return create(path, anti, Pic.default_space);
    }

    public static Pic create(File path, boolean anti, String space) {
        try {
            BufferedImage bf = ImageIO.read(path);
            int[][] data = new int[bf.getHeight()][bf.getWidth()];
            for (int y = 0; y < data.length; y++)
                for (int x = 0; x < data[y].length; x++)
                    data[y][x] = getVal(bf.getRGB(x, y));
            if (space == null || space.length() == 0) return create(data, anti, Pic.default_space);
            return create(data, anti, space);
        } catch (Exception e) {
            e.printStackTrace();
            return buildPic("", Pic.default_space);
        }
    }

    private static Pic create(int[][] data, boolean anti, String space) {
        StringBuilder sb = new StringBuilder();
        int flag = anti ? 1 : 0;
        for (int y = 0; y < data.length / 4; y++) {
            for (int x = 0; x < data[0].length / 2; x++) {
                int curr = 0, add = 1, yc = 4 * y, xc = x * 2;
                for (int xt = 0; xt < 2; xt++)
                    for (int yt = 0; yt < 3; yt++) {
                        if (data[yc + yt][xc + xt] == flag) curr += add;
                        add <<= 1;
                    }
                for (int xt = 0; xt < 2; xt++) {
                    if (data[yc + 3][xc + xt] == flag) curr += add;
                    add <<= 1;
                }
                sb.append(C[curr]);
            }
            sb.append("\n");
        }
        return buildPic(sb.toString().replace(String.valueOf(TEMP_CHAR), space), space);
    }

    private static int getVal(int n) {
        int res = 0;
        res += (n & 0b111111110000000000000000) >> 16;
        res += (n & 0b1111111100000000) >> 8;
        res += (n & 0b11111111);
        return res > 350 ? 1 : 0;
    }

    public static String reverse(String pic) {
        return reverse(pic, Pic.default_space);
    }

    private static String reverse(String pic, String space) {
        if (pic == null) return null;
        if (space == null || space.length() == 0) return reverse(pic, Pic.default_space);
        StringBuilder sb = new StringBuilder();
        for (char c : pic.replace(space, String.valueOf(TEMP_CHAR)).toCharArray())
            sb.append(RC.getOrDefault(c, c));
        return sb.toString().replace(String.valueOf(TEMP_CHAR), space);
    }

    public static String toSafe(String pic) {
        return toSafe_D(pic, String.valueOf(SINGLE_BULL_20));
    }

    public static String toSafe_D(String pic, char... replace) {
        if (replace == null || replace.length == 0) return toSafe_D(pic, String.valueOf(SINGLE_BULL_20));
        return toSafe_D(pic, String.valueOf(replace));
    }

    public static String toSafe_D(String pic, String replace) {
        if (pic == null) return null;
        if (replace == null || replace.length() == 0) return toSafe_D(pic, String.valueOf(SINGLE_BULL_20));
        return pic.replace(Pic.default_space, replace);
    }

    public static String toNormal(String pic) {
        if (pic == null) return null;
        return toSafe_D(pic, String.valueOf(SPACE_BRAILLE));
    }

    public static String changeDefaultSpace(String spaces) {
        if (spaces == null || spaces.length() == 0)
            return changeDefaultSpace(O_D_SPACE);
        String old = Pic.default_space;
        Pic.default_space = spaces;
        return old;
    }

    public static String changeDefaultSpace(char... spaces) {
        if (spaces == null || spaces.length == 0) return changeDefaultSpace(O_D_SPACE);
        return changeDefaultSpace(new String(spaces));
    }

    private static Pic buildPic(String pic, String space) {
        Pic res = new Pic();
        res.currentPicture = pic;
        res.space = space;
        return res;
    }





    private String currentPicture = "";
    private String space = Pic.default_space;
    private boolean changeable = false;

    private Pic() {
    }
    
    public Pic(Pic another) {
        this.currentPicture = another.currentPicture;
        this.space = another.space;
        this.changeable = another.changeable;
    }

    public Pic(File path) {
        this(path, false, Pic.default_space);
    }

    public Pic(File path, boolean anti) {
        this(path, anti, Pic.default_space);
    }

    public Pic(File path, String space) {
        this(path, false, space);
    }

    public Pic(File path, boolean anti, String space) {
        this.currentPicture = create(path, anti, space).currentPicture;
        this.space = space;
    }

    public Pic(String pic) {
        this(pic, Pic.default_space);
    }

    public Pic(String pic, char... spaces) {
        if (spaces == null || spaces.length == 0) this.space = Pic.default_space;
        else this.space = String.valueOf(spaces);
        this.currentPicture = Pic.initialPictureString(pic, this.space);
    }

    public Pic(String pic, String space) {
        if (space == null || space.length() == 0) this.space = Pic.default_space;
        else this.space = space;
        this.currentPicture = Pic.initialPictureString(pic, this.space);
    }

    private static String initialPictureString(String pic, String space) {
        if (pic == null) return "";
        StringBuilder sb = new StringBuilder();
        boolean out = false;
        for (char c : pic.replace(space, String.valueOf(TEMP_CHAR)).toCharArray()) {
            if (RC.containsKey(c)) sb.append(c);
            else {
                sb.append(TEMP_CHAR);
                out = true;
            }
        }
        String res = sb.toString().replace(String.valueOf(TEMP_CHAR), space);
        if (out) new RuntimeException("PictureString contains undefined character. SpaceCharacters ["
                + space + "] have took place of them.").printStackTrace();
        return res;
    }

    public Pic toSafe() {
        return this.toSafe_D(String.valueOf(SINGLE_BULL_20));
    }

    public Pic toSafe_D() {
        return this.toSafe_D(String.valueOf(SINGLE_BULL_20));
    }

    public Pic toSafe_D(char... replace) {
        if (replace == null || replace.length == 0) return this.toSafe_D(String.valueOf(Pic.SINGLE_BULL_20));
        return this.toSafe_D(String.valueOf(replace));
    }

    public Pic toSafe_D(String replace) {
        if (replace == null || replace.length() == 0) return toSafe_D(String.valueOf(Pic.SINGLE_BULL_20));
        return getReturn(this.currentPicture.replace(this.space, replace), this.space);
    }

    public Pic toNormal() {
        return this.toSafe_D(String.valueOf(SPACE_BRAILLE));
    }

    public Pic reverse() {
        return getReturn(Pic.reverse(this.currentPicture, this.space), this.space);
    }

    public Pic changeSpace(char... newSpaces) {
        if (newSpaces == null || newSpaces.length == 0) return changeSpace(O_D_SPACE);
        return changeSpace(String.valueOf(newSpaces));
    }

    public Pic changeSpace(String newSpace) {
        if (newSpace == null || newSpace.length() == 0) return changeSpace(O_D_SPACE);
        return getReturn(this.currentPicture.replace(this.space, newSpace), newSpace);
    }

    public String getSpace() {
        return this.space;
    }

    public Pic reCreate(File path) {
        return reCreate(path, false);
    }

    public Pic reCreate(File path, boolean anti) {
        return getReturn(create(path, anti, this.space).currentPicture, this.space);
    }

    public Pic reCreate(String pic) {
        return getReturn(initialPictureString(pic, this.space), this.space);
    }

    public Pic changeable() {
        return setChangeable(true);
    }

    public Pic unchangeable() {
        return setChangeable(false);
    }

    public Pic setChangeable(boolean changeable) {
        this.changeable = changeable;
        return this;
    }

    private Pic getReturn(String pic, String space) {
        if (this.changeable) {
            this.currentPicture = pic;
            return this;
        }
        return Pic.buildPic(pic, space);
    }

    @Override
    public String toString() {
        return this.currentPicture;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || this.getClass() != o.getClass()) return false;
        Pic pic = (Pic) o;
        return this.changeable == pic.changeable &&
                Objects.equals(this.currentPicture, pic.currentPicture) && 
                Objects.equals(this.space, pic.space);
    }

    @Override
    public int hashCode() {
        return this.currentPicture.hashCode();
    }
}

点阵图生成器
https://i-melody.github.io/2023/04/17/杂项/点阵图生成器/
作者
Melody
发布于
2023年4月17日
许可协议