ASCII-Art-Generator
zelin
15
Visit GitHub RepoBitmaps

ASCII-Art-Generator

Version Platform License Donate Bitcoin

Screenshot 1 Screenshot 2

Installation

The easiest way to add the library to your project is by adding it as a dependency to your build.gradle

dependencies {
   implementation 'com.neberox.library:asciicreator:0.0.1'
}

Usage

Using ASCIIConverter class

Create a ASCIIConverter object

ASCIIConverter converter = new ASCIIConverter();

Create ASCII from bitmap

Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.test_image);
imgView.setImageBitmap(converter.createASCIIImage(bitmap));

Convert in the background async task providing a completion block. Completion block will be called on the main thread.

converter.createASCIIImage(bitmap, new OnBitmapTaskListener()
{
    @Override
    public void onTaskCompleted(Bitmap data)
    {
        imgView.setImageBitmap(data);
    }
});

Convert to String

Log.d("ASCII-GENERATOR", converter.createASCIIString(bitmap));

Convert in the background async task providing a completion block. Completion block will be called on the main thread.

converter.createASCIIString(bitmap, new OnStringTaskListener()
{
    @Override
    public void onTaskCompleted(String data)
    {
        Log.d("ASCII-GENERATOR", data);
    }
});

Options available

converter.setFontSize(18);
converter.setReversedLuminance(false);
converter.setGrayScale(false);
converter.setBackgroundColor(Color.RED);

More Options

By default luminance values are mapped to strings using

Map<String, Float> map = new HashMap<String, Float>();
map.put(" ", 1.0f);
map.put("`", 0.95f);
map.put(".", 0.92f);
map.put(",", 0.9f);
map.put("-", 0.8f);
map.put("~", 0.75f);
map.put("+", 0.7f);
map.put("<", 0.65f);
map.put(">", 0.6f);
map.put("o", 0.55f);
map.put("=", 0.5f);
map.put("*", 0.35f);
map.put("%", 0.3f);
map.put("X", 0.1f);
map.put("@", 0.0f);

You can instantiate a converter with your own map

Map<String, Float> map = new HashMap<String, Float>();
map.put(" ", 1.0f);
map.put("`", 0.95f);
map.put(",", 0.9f);
map.put("-", 0.8f);
map.put("+", 0.7f);
map.put("<", 0.65f);
map.put("o", 0.55f);
map.put("=", 0.5f);
map.put("%", 0.3f);
map.put("@", 0.0f);

converter = new ASCIIConverter(Activity.this, map)

Potential Improvements

  • Creating an ASCIIImageView to automatically generate ASCII from bitmap
  • Implementing more options for creating ASCII

Author

Muhammad Umar, https://github.com/zelin

License

ASCII-Art-Generator is available under the MIT license. See the LICENSE file for more info.

Become a better Android Developer
Millions of developers are learning at MindOrks

Online Training Program

Featured Blogs

Our Team

MindOrks is Certainly one of the best online blog to stay on top of all the Android development news, coding and design patterns. Finally a blog I can count on to keep myself updated with latest and greatest things happening in Android world.

Vipul Shah
Android Developer
Microsoft

Become Pro in Android by watching videos

OUR LEARNERS WORK AT