How can I calculate the UIImage cropping size (rect) with different resolution

In my application, I have the "Capture from Camera" function, I use GPUImageFramework from Brad Larson (ty), GPUImageStillCamera when capturing still images.

stillCamera = [[GPUImageStillCamera alloc] initWithSessionPreset:AVCaptureSessionPresetPhoto cameraPosition:
               AVCaptureDevicePositionBack];

as you can see. The pre-set session AVCaptureSessionPresetPhoto, which on iPhone 4 gives me 1529x2048 output, and the 4s (8mp) device gives me 2448x3264.

The following shows how I use GPUStillCamera. there is a rectangle, which in this case is a crop of the captured image.

Still camera output

code snippet when capturing an image.

- (IBAction)takePhoto:(id)sender
{
        [stillCamera capturePhotoAsJPEGProcessedUpToFilter:filter withCompletionHandler:^(NSData *processedJPEG, NSError *error){

        //1529x2048 when iPhone 4 and 2448x3265 when on 4s
        UIImage *rawImage = [[UIImage alloc]initWithCGImage:[[UIImage imageWithData:processedJPEG]CGImage]scale:1.0 orientation:UIImageOrientationUp];

       **CGRect rect = CGRect{?,?,?,?};**
       UIImage *imageFromRect = [rawImage imageAtRect:rect ];
}

. (x, y, w, h), imageAtRect, rawImage? ( ), ? , ?

!

+5

All Articles