我看到很多教程有關裁剪圖像並正嘗試我的運氣,但沒有成功。
我需要從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
請參閱http://stackoverflow.com/questions/158914/cropping-a-uiimage – Spynet
@Spynet我試過了代碼。它不裁剪我的圖像,這是高分辨率 – Dejell
圖像的大小是多少 – Spynet