My task is to cut a square from a rectangular JPEG image, without losing quality. I have the coordinates of the square in relation to the rectangle. How should I face this problem?

Is there any API that would allow me to operate directly on the JPEG image - create a new JPEG image containing the defined square?

If I have to operate on bitmaps, how do I deal with memory constraints? If the image is from a 5megapixel camera, the bitmap will use quite a lot of memory. How do I cut out a part of a bitmap?

Thank you for any suggestions.