Add text into image and share as a img file android

Viewed 59

I am trying to make an app like HBD wish sharing app but I want to add text to the image and share it as an image file. add text in the image in Relative Layout is simple but I want to share that image and text as an image file. my app maybe it looks like a certificate generator(sololearn app for example)

                                  Thank You
1 Answers

Just pass the id of the relative layout in here and it will return a bitmap of that entire view. You can then save that as a PNG file and you're good to go.

private Bitmap getBitmapFromView(View view) {
    view.setDrawingCacheEnabled(true);

    Bitmap returnedBitmap = view.getDrawingCache();
    Canvas canvas = new Canvas(returnedBitmap);
    Drawable bgDrawable =view.getBackground();
    if (bgDrawable!=null) {
        bgDrawable.draw(canvas);
    }   else{
        canvas.drawColor(Color.WHITE);
    }
    view.draw(canvas);
    return returnedBitmap;
}
Related