Home PC Games Linux Windows Database Network Programming Server Mobile  
  Home \ Programming \ Generated characters using Java Videos     - Linux (SUSE) mount NTFS mobile hard practice (Linux)

- Binary Tree Traversal (Linux)

- Web server security policy (Linux)

- Linux kernel socket protocol stack routing lookup cache mechanism (Linux)

- Linux Getting Started tutorial: Experience Xen Virtual Machine chapter (Linux)

- Spark local development environment to build (Server)

- Getting Started with Linux: Learn how to upgrade Docker in Ubuntu (Server)

- Fedora 21 setting boot script (Linux)

- Apache Linux firewall reverse proxy configuration (Linux)

- Linux Shell Scripting Interview Question (Linux)

- Android custom slideshow menu slidmenu (Programming)

- Distributed File System using MogileFS (Linux)

- iostat command Detailed (Linux)

- Linux iptables port mapping settings (Server)

- openSUSE 13.1 / 13.2 installation SoundConverter 2.1.2 (Linux)

- Variables Python variables (Programming)

- Linux cron job (Linux)

- Glibc support encryption by modifying the DNS (Programming)

- TeamCity continuous integration in the Linux installation (Linux)

- Android Dynamic efficiency articles: a brilliant Loading Analysis and Implementation (Programming)

  Generated characters using Java Videos
  Add Date : 2017-04-19      
  To ASCII art is a technique that uses standard ASCII printable characters to produce visual artistic effect. Historically it has a purpose of its existence, when the printer can not print the image, and the image was embedded in the message also can not be achieved, it is also used in the mail. In this article, I'll show you a very simple code ASCII Art Generator, which is written in Java, and you can configure the font and contrast. Because the generator is I created a couple of hours on the weekend, so it's not perfect, but it is an interesting experiment. Below you can see the realization of the code, and I'll explain how it works.


This algorithm is very simple. First, we will use the ASCII art in each of the characters to be converted into an image, and caches it. Then, we traverse the original image, character size for each image block, can find the best match its character. In order to achieve this step, we first do some pre-processing of the original image: we convert the image to grayscale and then allowed to filter through a threshold value, then you get a black and white contrast chart, we can be with each Compare and calculate the difference between the characters. Next, each image block to select the most similar character, always continue until the entire image conversion is complete. In addition, we may also need to be adjusted according to the size of the threshold value to influence the contrast and enhance the final result.

To achieve this, a very simple method is to red, green, and blue values ​​are set to the average of three colors:

Red = green = blue = (red + green + blue) / 3

If this value is below the threshold, we will set it to white, otherwise we will be set to black. Finally, the image of each character to pixel comparison unit and calculate the average error.

int r1 = (charPixel >> 16) & 0xFF;
int g1 = (charPixel >> 8) & 0xFF;
int b1 = charPixel & 0xFF;

int r2 = (sourcePixel >> 16) & 0xFF;
int g2 = (sourcePixel >> 8) & 0xFF;
int b2 = sourcePixel & 0xFF;

int thresholded = (r2 + g2 + b2) / 3 < THRESHOLD 0: 255;?

error = Math.sqrt ((r1 - thresholded) * (r1 - thresholded) +
    (G1 - thresholded) * (g1 - thresholded) + (b1 - thresholded) * (b1 - thresholded));

Because the color is stored in a single integer, so we first extract a single color component and perform the calculation I explained above. Another challenge is to accurately measure the size of the character, and they plotted to center. After the test a variety of methods, I have found this method is good enough:

Rectangle rect = new TextLayout (Character.toString ((char) i), fm.getFont (),
    . Fm.getFontRenderContext ()) getOutline (null) .getBounds ();

g.drawString (character, 0, (int) (rect.getHeight () - rect.getMaxY ()));

You can download the complete source code from GitHub.
- Ubuntu 14.10 PPA installed Android Studio (Linux)
- dmidecode command Detailed (Hardware information) (Linux)
- On event processing browser compatibility notes (Programming)
- MySQL binary packages install for RedHat Linux Enterprise 6.4 (Database)
- Shell Programming Regular Expressions (Programming)
- Spring Integration ehcache annotation implement the query cache and cache update or delete instant (Programming)
- To install the Git and Github under Ubuntu (Linux)
- In addition to wget and curl, what better alternatives (Linux)
- iOS persistence of data archiving NSKeyedArchiver (Programming)
- Linux Log File Browser --logrotate (Linux)
- Oracle database, some basic grammatical structures (Database)
- Create the best introductory tutorial REST API (Linux)
- How apt-get limited use IPv4 or IPv6 protocol to download (Linux)
- Analysis of MySQL High Availability (Database)
- Installation under Linux Mint system guidelines for Gtk (Linux)
- Ubuntu compiler installation R Full Record (Linux)
- vector C ++ sequence containers (Programming)
- Workaround CentOS error message during compilation PHP5 common (Linux)
- Docker - for the development and deployment of unified lightweight Linux containers (Linux)
- Java to create a table in the database SYBase (Database)
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.