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'
}
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);
}
});
converter.setFontSize(18);
converter.setReversedLuminance(false);
converter.setGrayScale(false);
converter.setBackgroundColor(Color.RED);
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)
- Creating an ASCIIImageView to automatically generate ASCII from bitmap
- Implementing more options for creating ASCII
Muhammad Umar, https://github.com/zelin
ASCII-Art-Generator is available under the MIT license. See the LICENSE file for more info.