Ben Holland Ben Holland - 3 months ago 18
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

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);
Comments