Answer the question
In order to leave comments, you need to log in
How to save a fully rendered ScrollView to a Bitmap?
Here is the code:
public static Bitmap getBitmapFromView(View view, int totalHeight, int totalWidth) {
Bitmap returnedBitmap = Bitmap.createBitmap(totalWidth,totalHeight , 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;
}
Answer the question
In order to leave comments, you need to log in
You forgot to call a method measure
Fix it like this:
public static Bitmap getBitmapFromView(View view, int totalHeight, int totalWidth) {
Bitmap returnedBitmap = Bitmap.createBitmap(totalWidth,totalHeight , 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.measure( View.MeasureSpec.makeMeasureSpec(totalWidth,View.MeasureSpec.EXACTLY),
View.MeasureSpec.makeMeasureSpec(totalHeight,View.MeasureSpec.EXACTLY));
view.layout(0,0,totalWidth,totalHeight);
view.draw(canvas);
return returnedBitmap;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question