首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >旋转UIImage给出空白UIImage

旋转UIImage给出空白UIImage
EN

Stack Overflow用户
提问于 2011-11-20 17:14:10
回答 1查看 550关注 0票数 0

我想用这种方法将UIImage旋转90度:

代码语言:javascript
复制
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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-11-20 17:34:46

以下是代码:

代码语言:javascript
复制
UIImage *PortraitImage;
PortraitImage  = [[UIImage alloc] initWithCGImage: currentImage.CGImage
                                                    scale: 1.0
                                              orientation: UIImageOrientationLeft];

如果你想以某个特定的角度旋转UIImage,那么你可以使用CIIFilter来旋转任何你想要的角度,但这在iOS5.0中是可能的

代码语言:javascript
复制
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];
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8200543

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档