Android Guide: How to draw text over bitmap

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.

Do you need more detailed help? Book a consultation:
Let’s chat about it


Viktor De Pasquale


Author picture

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

Load more
Leave a comment

Instead of great success we have experienced great entrepreneurship lessons (for now). It also transformed me, a person who has never worked in IT before, into the app project/product manager. I once took part in a workshop, which encouraged people to invest in their idea and start ...

Read post

  Project Čestina 2.0 covering a variety of the modern Czech language with its slangs and new words has joined forces with vocabulary Flashcard app Vocabulary Miner. They are bringing new words not only to Czechs but ...

Read post

  The most popular higher-order functions are map, filter, and reduce. We all use them since we think that syntax is much better and it is even faster to write them than the old way for-in loop. But is it really true ...

Read post

In order to allow our CI server to deploy applications on Google Play automatically, we have to generate the JSON key. This whole process has three parts: Create a Service account Generate the key Grant access to our key Thanks to this key, we can quickly deploy applications ...

Read post