Take a screenshot of a whole View
Actually I found the answer:
public static Bitmap loadBitmapFromView(View v) {
Bitmap b = Bitmap.createBitmap(v.getWidth() , v.getHeight(), Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(b);
v.draw(c);
return b;
}
Take whole Screenshot of a scrollable View
I hope this is work for you.. source here. this is not technically a screenshot code. but this code convert the whole layout view into bitmap
Bitmap bitmap = getBitmapFromView(scrollview, scrollview.getChildAt(0).getHeight(), scrollview.getChildAt(0).getWidth());
//create bitmap from the ScrollView
private Bitmap getBitmapFromView(View view, int height, int width) {
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
Drawable bgDrawable = view.getBackground();
if (bgDrawable != null)
bgDrawable.draw(canvas);
else
canvas.drawColor(Color.WHITE);
view.draw(canvas);
return bitmap;
}
How to take screenshot of WHOLE activity page programmatically?
One way is to extract the bitmap of the current screen and save it. Try this:
public void takeScreenshot(){
Bitmap bitmap = getScreenBitmap(); // Get the bitmap
saveTheBitmap(bitmap); // Save it to the external storage device.
}
public Bitmap getScreenBitmap() {
View v= findViewById(android.R.id.content).getRootView();
v.setDrawingCacheEnabled(true);
v.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
v.layout(0, 0, v.getMeasuredWidth(), v.getMeasuredHeight());
v.buildDrawingCache(true);
Bitmap b = Bitmap.createBitmap(v.getDrawingCache());
v.setDrawingCacheEnabled(false); // clear drawing cache
return b;
}
Android take screen shot programmatically
What is the simplest way to get screenshot in android using kotlin?
Add desired views in xml layout inflate it and take screenshot of parent layout that is containing your views.
Code for taking screenshoot:
fun takeScreenshotOfView(view: View, height: Int, width: Int): Bitmap {
val bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888)
val canvas = Canvas(bitmap)
val bgDrawable = view.background
if (bgDrawable != null) {
bgDrawable.draw(canvas)
} else {
canvas.drawColor(Color.WHITE)
}
view.draw(canvas)
return bitmap
}
Related Topics
This Version of the Application Is Not Configured for Billing Through Google Play
Android Preventing Double Click on a Button
How to Provide Shadow to Button
What Exactly Does the Post Method Do
Android Singletask or Singleinstance Launch Mode
How to Access Call Log for Android
Passing Data Between Fragments to Activity
Strange Behavior with Android Orientation Sensor
How Does One Use Glide to Download an Image into a Bitmap
How to Capture the Android Device Screen Content
What Is an Android Pendingintent
How to Programmatically Open the Permission Screen for a Specific App on Android 6.0 (Marshmallow)
Android: Taking Complete Control of Phone(Kiosk Mode), Is It Possible? How
Calling Activity Class Method from Service Class