Q:

Crop an image to a fixed size

I'm capturing an image with the camera, then I'm saving it into a Bitmap. I'm looking forward to center-crop that image, to 600x600px.
Something like this I've found:
https://stackoverflow.com/a/6909144/1943607
However, I can't find out how can I set a fixed with & height.
I'm soo bad at drawing images and canvas. It seems to be so abstract for me.
Thank you.

A:

This is exactly what you need.
// Returns an immutable bitmap from the specified subset of the source bitmap.
static Bitmap createBitmap(Bitmap source, int x, int y, int width, int height)

I don't really know if (0,0) is top-left or center, but I believe it's top-left.
* (0,0)

*~~~~~~+===========+
'      '           |
'      ' 200       |
'      '           |
+~~~~~~+           | 400
|  100             |
|                  |
|                  |
+==================+
        300

If it's indeed the center then:
x should be width /2
y    >>     height/2

Otherwise if it's top left:
x should be width /2 - cropWidth/2
y    >>     height/2 - cropHeight/2

On both occasions would look like this.
* (150,200)

+==================+
|                  |
|     +~~~~~~+     |
|     '      '     |
|     '  *   '200  | 400
|     '      '     |
|     +~~~~~~+     |
|       100        |
+==================+
        300

