Android Guide: How to draw text over bitmap

25.9.2018

Last Updated on

We’ve all been there,… reducing the number of overdraws or customizing image with little to none external libraries. This modern twist to this (and this) age-old article will surely help you with that.

I’ve managed to rewrite the example code in Kotlin so it’s far more readable than Java-stic code and you can understand what is really going on just by glancing over it.

bitmap programming

It is however backward compatible with Java, don’t you worry! It utilizes simple builder which gets you to set up quickly and you’ll get things done with just a few lines.


This is how it works:

  1. After you create the instance of DrawingConfig, it automatically sets default values to avoid nullability issues.
  2. You just set your paint, text and a background and call draw() , it spits out Bitmap with text on top of it just like a magic spell.
  3. (Non-mandatory step) You can adjust how the text is painted or even add own layout with some other content by calling draw {} , it gives you the instance of current DrawingValues and you are free to position the text wherever you like.

No further delay, here’s the code!

Whenever you feel like you would do something better, ping me in comments so others don’t do the same mistakes by copy-pasting this code.

 

Viktor De Pasquale

Comments

Author picture

You’re on top of the game. Thanks for shgarni.

Reply
Load more
Leave a comment

  Twitter is there to enhance your Android skills. How? Just follow the right people and get your feed updated with Android insights and hacks. If you are from the Czech Republic or Slovakia, you can be surely inspired by your local Slovak and Czech ...

Read post

  Twitter can definitely educate the Android Developer you are. It is as easy as to follow the right people and then just checking their regular insights in your feed.  The only thing that remains is how to choose the right people.  And we can try to help you with ...

Read post

The Flashcard maker app Vocabulary Miner by Czech SKOUMAL Studio helps memorize vocabulary that the user really needs. Now, topical Word lists tailored to the needs of expats and travelers are available in 12 languages. Users can effectively learn Czech ...

Read post

  Have you ever felt like Google Play is discriminating against your app? You are not alone. What is the real problem? Google Play was re-branded from Android Market a few years back. Many features have been redone, removed or added since then, but things like rating stay ...

Read post