Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/design-patterns/2.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
Iphone 旋转UIImage可生成空白UIImage_Iphone_Objective C - Fatal编程技术网

Iphone 旋转UIImage可生成空白UIImage

Iphone 旋转UIImage可生成空白UIImage,iphone,objective-c,Iphone,Objective C,我想使用此方法将UIImage旋转90度: static inline double radians (double degrees) {return degrees * M_PI/180;} UIImage* rotate(UIImage* src, UIImageOrientation orientation) { UIGraphicsBeginImageContext(src.size); CGContextRef context = UIGraphicsGetCurre

我想使用此方法将UIImage旋转90度:

static inline double radians (double degrees) {return degrees * M_PI/180;}
UIImage* rotate(UIImage* src, UIImageOrientation orientation)
{
    UIGraphicsBeginImageContext(src.size);

    CGContextRef context = UIGraphicsGetCurrentContext();

    if (orientation == UIImageOrientationRight) {
        CGContextRotateCTM (context, radians(90));
    } else if (orientation == UIImageOrientationLeft) {
        CGContextRotateCTM (context, radians(-90));
    } else if (orientation == UIImageOrientationDown) {
        // NOTHING
    } else if (orientation == UIImageOrientationUp) {
        CGContextRotateCTM (context, radians(90));
    }

    [src drawAtPoint:CGPointMake(0, 0)];

    return UIGraphicsGetImageFromCurrentImageContext();
}
问题是它给了我一个空白的UIImage

以下是代码:-

UIImage *PortraitImage;
PortraitImage  = [[UIImage alloc] initWithCGImage: currentImage.CGImage
                                                    scale: 1.0
                                              orientation: UIImageOrientationLeft];
如果您想以某个特定角度旋转UIImage,则可以使用CIIFilter以任意角度旋转UIImage,但这在IOS 5.0中是可能的

CIImage *inputImage = [[CIImage alloc] initWithImage:[UIImage imageNamed:@"old-country-rain.jpg"]];
CIFilter *RotateFilter = [CIFilter filterWithName:@"CIStraightenFilter"];
[RotateFilter setValue:[NSNumber numberWithFloat: 1.04667f]  forKey:@"inputAngle"];
[RotateFilter setValue:inputImage forKey:kCIInputImageKey];
CIImage *displayImage = RotateFilter.outputImage;
UIImage *finalImage = [UIImage imageWithCIImage:displayImage];

我发现图像范围在旋转后不会改变。有什么建议吗?我的图像的displayImage.extents是640 x 480。旋转后,displayImage.extents仍为640 x 480。