Library Color to ASCII+Chatcolors - Create ASCII art.

Discussion in 'Resources' started by Zombie_Striker, Jan 2, 2017.

Thread Status:
Not open for further replies.
  1. Offline


    What is this?
    This is a library I built for my PixelPrinter. This library allows you to turn raw Color codes into the closest matching ChatColor and Character combination. Since there does not seem to be a library out there that does the same thing, I figured I would post it here for someone else to use.

    If you want a finished product for this library (if you just want to load images on your server without coding), you can check out the plugin I made using this library.

    Why should I use this?
    Since this is meant to just turn Color Values into Colored Characters, you will only need this if you want to load images/ pixel art in chat.

    If you want to turn colors into blocks go to this library.

    Since this page would go over the char limit, you can find my code at the following repo:

    Below is the code for printing out the BufferedImage (named "bi") into chat. Eventually, I will create a method for handling all of this.

    Rember: The bufferedImage should be no more than 40 pixels high, as this turns 2 pixels into a single character and MC only loads 20 lines of chat.
        final Pixel[][] result = RGBChatColor
                   //Make sure the image is within bounds
                    int wMin = 0;
                    int wMax = bi2.getWidth();
                    if (wMax > 88) {
                        wMin = (bi2.getWidth() / 2) - 44;
                        wMax = wMin + 88;
                    for (int height = 0; height < (bi2.getHeight() - 1); height += 2) {
                        StringBuilder sb = new StringBuilder();
                        for (int width = wMin; width < wMax; width += 2) {
                            Color[] color = new Color[4];
                            int y = (height + 1 < result.length) ? height + 1
                                    : height;
                            int x = (width + 1 < result[y].length) ? width + 1
                                    : width;
                            color[0] = new Color(result[y][x - 1].r,
                                    result[y][x - 1].g, result[y][x - 1].b);
                            color[1] = new Color(result[y][x].r, result[y][x].g,
                            color[2] = new Color(result[y - 1][x - 1].r,
                                    result[y - 1][x - 1].g, result[y - 1][x - 1].b);
                            color[3] = new Color(result[y - 1][x].r,
                                    result[y - 1][x].g, result[y - 1][x].b);
                            String c = RGBChatColor.getClosestBlockValue(color);



    Init post
    Last edited: Jan 3, 2017
  2. Last edited: Jan 3, 2017
  3. Offline


    Thanks for pointing out the link error.

    Although Black Bar characters can be used (which is why I left it in there), I recommend using the other letters instead since they allow for slight variations between pixels.

    As for the color issue, that is WHITE/lightblue/yellow is the closest colors it can find. I was thinking of moving the white RGB value higher so it does not get picked as easily.

    [Edit]Since I do not know how you added the blackbar line, I'll post the line in the in the main post (with a better description of how to use and edit my code) and down here. Since BlackBar takes up a full character and there should be no gap between each character, the color for the RGB should be 255,255,255. This is what you should be using to add it:
        addColor(BLACK_BAR, new double[] { 255, 255, 255 ,255 }, new double[] {255, 255, 255 ,255 }, new double[] {255, 255, 255 ,255 });
    Since I have also been noticing that most of the colors get washed out, I will try to make an update to the code is it will either avoid white unless it the color is actually very close to being white.
Thread Status:
Not open for further replies.

Share This Page