0

I have imported a photo from gallery now i want some predefined text on this photo and then save it with with the new text appeared on the photo.

2 Answers2

0

Convert the JPG image to a bitmap. Once it's a bitmap, you can use Canvas APIs. See this answer for an example.

acallan
  • 34
  • 2
0

This is how you do first You need to get that photo (Bitmap) now and get a reference say:

        Bitmap bitmap = ... // Bitmap Photo Here the one you have loaded

The to apply color use Canvas as:

        Canvas canvas = new Canvas(bitmap);
        Paint paint = new Paint(); 
        paint.setColor(Color.BLACK); 
        paint.setTextSize(10); 
        canvas.drawText("Your text should go here!", x, y, paint);

x and y are locations you want the text to appear in the bitmap!

Thes finally save the Bitmap back to a location/file path you want

    FileOutputStream out = null;
    try {
      out = new FileOutputStream(`"your file path here"`); //check how to set a file path if you save it in sd card remember to have permissions and also runtime permission for devices like marshamallow and above
      bitmap.compress(Bitmap.CompressFormat.PNG, 100, out); 
      // PNG is a lossless format, the compression factor (100) is ignored
    } catch (Exception e) {
    e.printStackTrace();
    } finally {
       try {
           if (out != null) {
              out.close();
              }
       } catch (IOException e) {
           e.printStackTrace();
       }
    }

If you you are going to write it in external storage remember to have all the necessary write permission!

Xenolion
  • 12,035
  • 7
  • 33
  • 48