UIImage调整方向填充和裁剪

我有这个代码,我用这个尺寸的照片2448×3264,我需要resize,并调整到左上angular的屏幕显示。 对不起,我的英语感谢

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { imagenUsr = [info objectForKey:UIImagePickerControllerOriginalImage]; NSLog(@"%f",imagenUsr.size.height); //2448px NSLog(@"%f",imagenUsr.size.width); //3264px } 

我需要调整到320×568的方面,以填补所拍摄的图像的顶部和左侧

尝试这个:

 - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { imagenUsr = [info objectForKey:UIImagePickerControllerOriginalImage]; double width = imagenUsr.size.width; double height = imagenUsr.size.height; double screenWidth = self.view.frame.size.width; double apect = width/height; double nHeight = screenWidth/ apect; self.imgView.frame = CGRectMake(0, 0, screenWidth, nHeight); self.imgView.center = self.view.center; self.imgView.image = imagenUsr; } 

这将帮助您像以前一样保持宽高比。

另一种方法是:

 self.imgView.contentMode = UIViewContentModeScaleAspectFit; self.imgView.image = imagenUsr; 

希望这可以帮助.. :)

编辑:不知道如果我错过了这个或它被编辑,但我没有看到你想要裁剪以及。 拉沙德的解决scheme应该为你工作。

你有没有尝试与图像创build一个图像视图,并将其添加到视图?

 - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { imagenUsr = [info objectForKey:UIImagePickerControllerOriginalImage]; UIImageView *imageView = [[UIImageView alloc] initWithFrame:self.view.frame]; imageView.image = imagenUsr; imageView.contentMode = UIViewContentModeScaleAspectFit; [self.view addSubview:imageView]; }