R
R
RusSanta2017-07-11 10:26:12
Android
RusSanta, 2017-07-11 10:26:12

How do I take the content of a fragment and convert it to a bitmap?

My problem is that I need, roughly speaking, to select photos, display them dynamically in a fragment, then, at the click of a button, save all the contents of this fragment in a bitmap, and then in pdf format
. But I don’t know how to turn to this content of the fragment, I thought that it was possible to somehow pull the canvas, but did not find a suitable method.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
RusSanta, 2017-07-11
@RusSanta

private Bitmap createBitmapFromView (View view) {
        Bitmap returnedBitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(),Bitmap.Config.ARGB_8888);
        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;
    }

If someone is interested, then I found such a code, maybe someone will come in handy.
If you have any comments on it, please comment.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question