Skip to content

Instantly share code, notes, and snippets.

@hellokaton
Created September 6, 2016 03:18
Show Gist options
  • Save hellokaton/b1e36449f4738d7d45fc4a886b429141 to your computer and use it in GitHub Desktop.
Save hellokaton/b1e36449f4738d7d45fc4a886b429141 to your computer and use it in GitHub Desktop.
BufferedImage image = new BufferedImage(144, 32, BufferedImage.TYPE_INT_RGB);
Graphics g = image.getGraphics();
g.setFont(new Font("Dialog", Font.PLAIN, 24));
Graphics2D graphics = (Graphics2D) g;
graphics.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
graphics.drawString("Hello World!", 6, 24);
ImageIO.write(image, "png", new File("text.png"));
for (int y = 0; y < 32; y++) {
StringBuilder sb = new StringBuilder();
for (int x = 0; x < 144; x++)
sb.append(image.getRGB(x, y) == -16777216 ? " " : image.getRGB(x, y) == -1 ? "#" : "*");
if (sb.toString().trim().isEmpty()) continue;
System.out.println(sb);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment