public static RenderedImage toRenderedImage (String[] rows)
    {
        // Create the DataBuffer to hold the pixel samples
        final int width = rows[0].length();
        final int height = rows.length;
        final int size = width * height;
        byte[] pixels = new byte[size];
        int index = 0;
        for (String row : rows) {
            for (int x = 0; x < width; x++) {
                pixels[index++] = (byte) decodeGray(row.charAt(x));
            }
        }
        DataBuffer dataBuffer = new DataBufferByte(pixels, size);

        // Create Raster
        WritableRaster writableRaster = Raster.createBandedRaster
            (dataBuffer, width, height,
             width,                      // scanlineStride
             new int[] {0},             // bankIndices,
             new int[] {0},             // bandOffsets,
             null);                     // location

        // Create the image
        BufferedImage bufferedImage = new BufferedImage
                (width, height, BufferedImage.TYPE_BYTE_GRAY);
        bufferedImage.setData(writableRaster);

        return bufferedImage;
    }