Ben Holland Ben Holland - 1 year ago 109
Java Question

How to write text on an image in Java (Android)

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:

How to write text on image in objective-c iPhone?

How can I load an image and write text to it using Java?

Answer Source

What about something like:

Bitmap bitmap = ... // Load your bitmap here
Canvas canvas = new Canvas(bitmap);
Paint paint = new Paint(); 
canvas.drawText("Some Text here", x, y, paint);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download