我想用这种方法将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
发布于 2011-11-20 17:34:46
以下是代码:
UIImage *PortraitImage;
PortraitImage = [[UIImage alloc] initWithCGImage: currentImage.CGImage
scale: 1.0
orientation: UIImageOrientationLeft];如果你想以某个特定的角度旋转UIImage,那么你可以使用CIIFilter来旋转任何你想要的角度,但这在iOS5.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];https://stackoverflow.com/questions/8200543
复制相似问题