![](/img/trans.png)
[英]How to rotate orientation of UIImage when application have only one orientation
[英]How to detect current orientation to rotate UIImage?
我正在实现拍照功能,并且遇到以下问题。
拍照后,我必须从原始图像中裁剪缩略图以制作头像图标。 但是,如果用户以横向拍摄照片,那就不好了。
步:
如何检测旋转UIImage的方向?
尝试以下代码
if (image.size.width > image.size.height ) // Landscape
{
}
else // Portrait
{
}
UIImage具有size
属性。 您可以使用它来查找image
的height
和width
。
因此,如果height
> width
则image
为纵向,否则为横向
使用此代码获取设备的方向。 根据设备方向可以设置图像方向
[[UIDevice currentDevice] orientation]
用这个:
#pragma mark - Image Picker Controller delegate methods
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
self.imageView.image = chosenImage;
switch (chosenImage.imageOrientation) {
case UIImageOrientationUp: //Left
break;
case UIImageOrientationDown: //Right
break;
case UIImageOrientationLeft: //Down
break;
case UIImageOrientationRight: //Up
break;
default:
break;
}
[picker dismissViewControllerAnimated:YES completion:NULL];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.