I have a CardView (with multiple items like imageView, textView, Buttons) in a RecyclerView. I want to get bitmap from this cardview. I tried a simple method of converting cardView into bitmap (convert a cardview to bitmap) but its not working properly. I only got the raw view of the card just like in xml without any updated items from a firebaseserver.
Asked
Active
Viewed 400 times
0
-
what do you mean with changed items from the server? – kingston May 20 '18 at 19:05
-
Code, please so we can actually know what is going on :) – MohammedAlSafwan May 20 '18 at 19:06
-
@kingston i mean updated items – Sheraz khaliq May 20 '18 at 19:24
2 Answers
1
CardView extend view, so you probably can convert it as any other view, try to pass the CardView into that function:
public static Bitmap getBitmapFromView(View view) {
//Define a bitmap with the same size as the view
Bitmap returnedBitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(),Bitmap.Config.ARGB_8888);
//Bind a canvas to it
Canvas canvas = new Canvas(returnedBitmap);
//Get the view's background
Drawable bgDrawable =view.getBackground();
if (bgDrawable!=null)
//has background drawable, then draw it on the canvas
bgDrawable.draw(canvas);
else
//does not have background drawable, then draw white background on the canvas
canvas.drawColor(Color.WHITE);
// draw the view on the canvas
view.draw(canvas);
//return the bitmap
return returnedBitmap;
}

Nirel
- 1,855
- 1
- 15
- 26
0
you are probably taking the screenshot of view before it is fully inflated. Try adding a 2 second delay or implement this on layout listener of the card view

Suhaib Roomy
- 2,501
- 1
- 16
- 22