Crop bottom portion of a bitmap programmatically
<p>I have a bitmap taken from a camera. I want to crop the image so it only leaves the bottom portion of it. The cropped image should be 80% less the height of the original bitmap, so I want only the 20% of the bottom part starting from the left edge.</p>

<p>I'm doing this explicitly in the code without any Android cropping intent whatsoever.</p>

<p>An image to visualize what I want to achieve:</p>

<p><a href="https://i.stack.imgur.com/su5Jk.png" rel="noreferrer"><img src="https://i.stack.imgur.com/su5Jk.png" alt="crop this"></a></p>

<p>I've managed to crop the top part of the bitmap by using this code:</p>

<pre><code>final Bitmap toBeCropped = BitmapFactory.decodeFile(mFile.getPath());

final BitmapFactory.Options bitmapOptions = new BitmapFactory.Options();
bitmapOptions.inTargetDensity = 1;
toBeCropped.setDensity(Bitmap.DENSITY_NONE);

int fromHere = (int) (toBeCropped.getHeight() * 0.2);
Bitmap croppedBitmap = Bitmap.createBitmap(toBeCropped, 0, 0, toBeCropped.getWidth(), fromHere);
mPreviewHalf.setImageBitmap(croppedBitmap);
</code></pre>

<p>But I couldn't find a way to start the cropping 80% from the top. I'm thinking of getting the y-coordinate of the Bitmap, so that I could crop any image sizes and always get the bottom portion only. But can anyone point to me how do I get this coordinate from a bitmap? Or do I have to take it from the layout itself?</p>