Iphone 旋转UIImage可生成空白UIImage
我想使用此方法将UIImage旋转90度: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
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。