zelin/ASCII-Art-Generator


An Android open source ASCII Art Generator from any image

Download


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"]]
        
        

Readme


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.1.0'
}

Usage

Using ASCIIConverter class

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)
        }
    }
})

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

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)

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.