Programmatically crop Android screen grab?

android, screenshot

Solution

You can try and use Bitmap.createBitmap on your screenshot before you send it.

Bitmap cropimg = Bitmap.createBitmap(originalImg, 0, 0, originalImg.width(), originalImg.height() - x)

'x' which is an `Integer` is the number of pixels that are cropped from the bottom of the image in this case. You can do certain modifications and crop accordingly to suit your requirement.

Hope it helps

Problem

I'm using the following (scavenged) code to take a 'screenshot' and `action_send` it. It's al lworking okay, the only problem is the image doesn't contain the status bar. I know why, I'm just not sure what to do about it. Is there any way I can crop the image programmatically, or set some kind of boundary before I make the `getDrawingCache()` call?? Thanks in advance! ``` View v1 = findViewById(android.R.id.content).getRootView(); v1.setDrawingCacheEnabled(true); Bitmap screenshot = Bitmap.createBitmap(v1.getDrawingCache()); v1.setDrawingCacheEnabled(false); String path = Images.Media.insertImage(getContentResolver(), screenshot, "title", null); Uri screenshotUri = Uri.parse(path); Intent sharingIntent = new Intent(Intent.ACTION_SEND); sharingIntent.setType("image/png"); sharingIntent.putExtra(Intent.EXTRA_STREAM, screenshotUri); startActivity(Intent.createChooser(sharingIntent, "Share image using")); ```

Original source