Step 1. Add the JitPack repository to your build file
Add it in your root settings.gradle at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
Add it in your settings.gradle.kts at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url = uri("https://jitpack.io") }
}
}
Add to pom.xml
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Add it in your build.sbt at the end of resolvers:
resolvers += "jitpack" at "https://jitpack.io"
Add it in your project.clj at the end of repositories:
:repositories [["jitpack" "https://jitpack.io"]]
Step 2. Add the dependency
dependencies {
implementation 'com.github.zelin:ASCII-Art-Generator:0.0.1'
}
dependencies {
implementation("com.github.zelin:ASCII-Art-Generator:0.0.1")
}
<dependency>
<groupId>com.github.zelin</groupId>
<artifactId>ASCII-Art-Generator</artifactId>
<version>0.0.1</version>
</dependency>
libraryDependencies += "com.github.zelin" % "ASCII-Art-Generator" % "0.0.1"
:dependencies [[com.github.zelin/ASCII-Art-Generator "0.0.1"]]
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.1.0'
}
Create a ASCIIConverter object
var converter: ASCIIConverter = ASCIIConverter(this);
Create ASCII from bitmap
val bitmap = BitmapFactory.decodeResource(resources, 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, object : OnBitmapTaskListener {
override fun onTaskCompleted(data: Bitmap?) {
// Switch to the main thread to update the UI
lifecycleScope.launch(Dispatchers.Main) {
binding.imageView.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, object : OnStringTaskListener {
override fun onTaskCompleted(data: String?) {
data?.let {
Log.d("ASCII-GENERATOR", it)
}
}
})
converter.setFontSize(18);
converter.setReversedLuminance(false);
converter.setGrayScale(false);
converter.setBackgroundColor(Color.RED);
By default luminance values are mapped to strings using
val map: MutableMap<String, Float> = HashMap()
map[" "] = 1.0f
map["`"] = 0.95f
map["."] = 0.92f
map[","] = 0.9f
map["-"] = 0.8f
map["~"] = 0.75f
map["+"] = 0.7f
map["<"] = 0.65f
map[">"] = 0.6f
map["o"] = 0.55f
map["="] = 0.5f
map["*"] = 0.35f
map["%"] = 0.3f
map["X"] = 0.1f
map["@"] = 0.0f
You can instantiate a converter with your own map
val map: MutableMap<String, Float> = HashMap()
map[" "] = 1.0f
map["`"] = 0.95f
map[","] = 0.9f
map["-"] = 0.8f
map["+"] = 0.7f
map["<"] = 0.65f
map["o"] = 0.55f
map["="] = 0.5f
map["%"] = 0.3f
map["@"] = 0.0f
converter = ASCIIConverter(Activity.this, map)
Muhammad Umar, https://github.com/zelin
ASCII-Art-Generator is available under the MIT license. See the LICENSE file for more info.