Search code examples
javaandroidimagetextpng

How to write text on an image


I can do this in Objective-C on the iPhone, but now I'm looking for the equivalent Android Java code. I can also do it in plain Java, but I don't know what the Android specific classes are. I want to generate a PNG image on the fly that has some text centered in the image.

public void createImage(String word, String outputFilePath){ 
    /* what do I do here? */ 
}

Relevant threads:


Solution

  • What about something like:

    Bitmap bitmap = ... // Load your bitmap here
    Canvas canvas = new Canvas(bitmap);
    Paint paint = new Paint(); 
    paint.setColor(Color.BLACK); 
    paint.setTextSize(10); 
    canvas.drawText("Some Text here", x, y, paint);