Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.amirqadir.screenshot;
- import android.app.Activity;
- import android.graphics.Bitmap;
- import android.graphics.Point;
- import android.graphics.Rect;
- import android.view.View;
- import java.io.FileOutputStream;
- import java.io.IOException;
- /**
- * Created by Amir Qadir on 8/21/2017.
- */
- public class Utility {
- public static Bitmap takeScreenshot(Activity activity)
- {
- View view = activity.getWindow().getDecorView();
- view.setDrawingCacheEnabled(true);
- view.buildDrawingCache();
- Bitmap b1 = view.getDrawingCache();
- Rect frame = new Rect();
- activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);
- int statusBarheight = frame.top;
- Point size = new Point();
- activity.getWindowManager().getDefaultDisplay().getSize(size);
- int width = size.x;
- int height = size.y;
- Bitmap b = Bitmap.createBitmap(b1,0,statusBarheight,width,height-statusBarheight);
- view.destroyDrawingCache();
- return b;
- }
- public static void savePic(Bitmap b,String strFilename)
- {
- FileOutputStream fos;
- try {
- fos = new FileOutputStream(strFilename);
- b.compress(Bitmap.CompressFormat.PNG,90,fos);
- fos.flush();
- fos.close();
- }catch(IOException e)
- {
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement