Iphone 裁剪从AVCaptureStillImageOutput拍摄的图像

Iphone 裁剪从AVCaptureStillImageOutput拍摄的图像,iphone,ios,objective-c,image,ios7,Iphone,Ios,Objective C,Image,Ios7,我正在尝试裁剪从AVCaptureStillImageOutput拍摄的图像,但无法正确裁剪到正确的矩形 我的相机视频预览是320x458帧,剪切矩形出现在这个预览帧中,其坐标和大小为CGRectMake(60、20、200、420) 拍完照片后,我收到了来自 NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageDataSampleBuffer]; UIImage *imag

我正在尝试裁剪从AVCaptureStillImageOutput拍摄的图像,但无法正确裁剪到正确的矩形

我的相机视频预览是320x458帧,剪切矩形出现在这个预览帧中,其坐标和大小为CGRectMake(60、20、200、420)

拍完照片后,我收到了来自

NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageDataSampleBuffer];
UIImage *image = [[UIImage alloc] initWithData:imageData];
UIImage *finalImage = [self cropImage:image];
之后,我尝试使用下面的函数裁剪尺寸为1080x1920的实际图像。我得到了一个任性的剪辑,结果图像是出了实际的矩形;(

在所附的图片中,我试图裁剪咖啡杯,但我得到的不是正确的裁剪图像


我在这方面也面临着困难,我认为你要做的是编写文件的图像,然后裁剪该图像或尝试解决方向问题。

我认为你应该使用PephotoOpeditor示例代码进行裁剪。它很容易使用。你可以从

- (UIImage *)cropImage:(UIImage *)oldImage {
    CGRect rect = CGRectMake(60, 20, 200, 420);
    CGSize boundSize = CGSizeMake(320, 458);

    float widthFactor = rect.size.width * (oldImage.size.width/boundSize.width);
    float heightFactor = rect.size.height * (oldImage.size.height/boundSize.height);
    float factorX = rect.origin.x * (oldImage.size.width/boundSize.width);
    float factorY = rect.origin.y * (oldImage.size.height/boundSize.height);

    CGRect factoredRect = CGRectMake(factorX,factorY,widthFactor,heightFactor);
    UIImage *croppedImage = [UIImage imageWithCGImage:CGImageCreateWithImageInRect([oldImage CGImage], factoredRect) scale:oldImage.scale orientation:oldImage.imageOrientation];
    return croppedImage;
}