Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在iOS中将UIImage转换为LandscapeRight_Ios_Xcode_Uiimage_Landscape Portrait_Uiimageorientation - Fatal编程技术网

在iOS中将UIImage转换为LandscapeRight

在iOS中将UIImage转换为LandscapeRight,ios,xcode,uiimage,landscape-portrait,uiimageorientation,Ios,Xcode,Uiimage,Landscape Portrait,Uiimageorientation,在我的应用程序中,我将库中的不同图像添加到一个数组中,然后将它们转换为幻灯片放映。我能够做到这一点,但我面临的唯一问题是不同图像的方向。我想要的是,当用户从库中选择图片时,在插入阵列之前,应该检查其方向,如果不是横向右侧,则应该将其旋转到横向右侧。我该怎么做?此外,旋转后的图像应为纵横比填充,即旋转后的图像侧面不应有黑色边距 另外,我想旋转UIImage,而不是UIImageView,因为有一些方法可以旋转UIImageView,但它们不符合我的要求。您可以像这样旋转图像: UIImage *n

在我的应用程序中,我将库中的不同图像添加到一个数组中,然后将它们转换为幻灯片放映。我能够做到这一点,但我面临的唯一问题是不同图像的方向。我想要的是,当用户从库中选择图片时,在插入阵列之前,应该检查其方向,如果不是横向右侧,则应该将其旋转到横向右侧。我该怎么做?此外,旋转后的图像应为纵横比填充,即旋转后的图像侧面不应有黑色边距


另外,我想旋转UIImage,而不是UIImageView,因为有一些方法可以旋转UIImageView,但它们不符合我的要求。

您可以像这样旋转图像:

UIImage *newImage = [[UIImage alloc] initWithCGImage: myImage.CGImage
                                                 scale: 1.0
                                           orientation: UIImageOrientationRight];
这将为您提供一个指针,然后您可以通过比较图像大小来决定是否旋转图像,例如:

if (myImage.size.width < myImage.size.height) {
   // its portrait, do the rotation
}
if(myImage.size.width
您可以像这样简单地旋转图像:

UIImage *newImage = [[UIImage alloc] initWithCGImage: myImage.CGImage
                                                 scale: 1.0
                                           orientation: UIImageOrientationRight];
这将为您提供一个指针,然后您可以通过比较图像大小来决定是否旋转图像,例如:

if (myImage.size.width < myImage.size.height) {
   // its portrait, do the rotation
}
if(myImage.size.width
旋转它们最合适的方式是什么?UIImage*newImage=[[UIImage alloc]initWithCGImage:myImage.CGImage比例:1.0方向:UIImageOrientationRight];如上所述,这是一种非常有效的旋转图像的方法!(只需在方向:参数中指定要旋转的方向)好的,旋转工作正常,但此条件存在问题。if(myImage.size.width