可能重复:
裁剪 UIImage
我看到了很多关于裁剪图像的教程,并且正在尝试我的运气,但没有成功。
我需要从 AVFoundation 裁剪图像。因为当从相机拍摄图像时,它从肖像模式向左旋转,我还需要向右旋转它,我的 x 和 y 是相反的。问题是,如果我将图像的帧发送到我希望它驻留的位置,在我看来,图像和矩形的大小没有相关性。
代码是:
@property (weak, nonatomic) IBOutlet UIView *videoPreviewView;
...
...
int width = videoPreviewView.frame.size.width;
int height = videoPreviewView.frame.size.height;
int x = videoPreviewView.frame.origin.x;
int y = videoPreviewView.frame.origin.y;
CGRect croprect = CGRectMake(y, x,height,width);
// Draw new image in current graphics context
CGImageRef imageRef = CGImageCreateWithImageInRect([sourceImage CGImage], croprect);
// Create new cropped UIImage
UIImage *resultImage = [UIImage imageWithCGImage:imageRef scale:[sourceImage scale] orientation:UIImageOrientationRight];
当我打印框架的大小时,我得到:
(4.5,69.5,310,310)
图像大小为:
(720,1280)
如何以任何图像分辨率执行裁剪?
我尝试将这些值与image.scale
- 但是,该值为 1.00