0

I am use screen capture, and want to crop bitmap programatically 150dp from bottom of screen. (Erase bitmap 150dp from bottom of screen)

How to do that?

This is image explanation: http://imgur.com/TP2ouVp

Edited. Full code for take screen shot:

public void takeScreenshot() {
    Date now = new Date();
    android.text.format.DateFormat.format("yyyy-MM-dd_hh:mm:ss", now);

    try {

        String folder_main = "APP_FOLDER";
        File f = new File(Environment.getExternalStorageDirectory(), folder_main);
        if (!f.exists()) {
            f.mkdirs();
        }

        // image naming and path  to include sd card  appending name you choose for file
        String mPath = Environment.getExternalStorageDirectory().toString() + "/APP_FOLDER/" + now + ".jpg";

        // create bitmap screen capture
        View v1 = getWindow().getDecorView().getRootView();
        v1.setDrawingCacheEnabled(true);

        Bitmap source = v1.getDrawingCache();
        int x = 0;
        int y = v1.getHeight() ;
        int width = source.getWidth() - x;
        int height = source.getHeight() - y;
        Bitmap bitmap =  Bitmap.createBitmap(source, x, y, width, height);

        v1.setDrawingCacheEnabled(false);

        File imageFile = new File(mPath);

        FileOutputStream outputStream = new FileOutputStream(imageFile);
        int quality = 100;
        bitmap.compress(Bitmap.CompressFormat.JPEG, quality, outputStream);
        outputStream.flush();
        outputStream.close();

        openScreenshotWhatsApp (imageFile);
    } catch (Throwable e) {
        // Several error may come out with file handling or OOM
        e.printStackTrace();
    }
}

I'm very confusing. Thanks

Bonnie7
  • 19
  • 1
  • 7
  • Have you tried with this int height = source.getHeight() - 150; – King of Masses Jul 25 '17 at 11:41
  • are you able to take any part of the screenshot atleast ? – King of Masses Jul 25 '17 at 11:41
  • With that code, cannot make a screen shot. But done with this code: // create bitmap screen capture View v1 = getWindow().getDecorView().getRootView(); v1.setDrawingCacheEnabled(true); Bitmap bitmap = Bitmap.createBitmap(v1.getDrawingCache()); v1.setDrawingCacheEnabled(false); – Bonnie7 Jul 25 '17 at 11:43
  • Ok then, after taking complete screenshot also you can crop the particular part which you want. try in that way, i m not sure – King of Masses Jul 25 '17 at 11:45
  • Sorry, I test again with: int y = v1.getHeight() -150 ; But just crop for 150dp from bottom of screen. I need erase 150dp from screen. – Bonnie7 Jul 25 '17 at 11:47

1 Answers1

1

Try this code

Call this method, passing in the outer most ViewGroup that you want a screen shot of:

public Bitmap screenShot(View view) {
    Bitmap bitmap = Bitmap.createBitmap(view.getWidth(),
            150, Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    view.draw(canvas);
    return bitmap;
}

For more you can check this answers as well

King of Masses
  • 16,881
  • 4
  • 57
  • 75