UIImage不会改变方向

时间:2011-11-16 19:33:22

标签: ios4

这行代码无效。它不会改变图像的方向。我做错了什么?

// image is of type UIImage
UIImage * newImage = [UIImage imageWithCGImage:[image CGImage] scale:image.scale orientation:UIImageOrientationLeft];

1 个答案:

答案 0 :(得分:0)

请参阅下面此方法的定义,确保您的CGImage是CGImageRef类。 imageWithCGImage:[image CGImage]

+(UIImage *)imageWithCGImage:(CGImageRef)imageRef scale:(CGFloat)scale orientation:(UIImageOrientation)orientation

在调用方法之前,有三行是一些初始化。

CIContext * context = [CIContext contextWithOptions:nil]; //your choice
CIImage * OriginalImage = [CIImage imageWithContentsOfURL:fileNameAndPath]; //your own choice of source image file.

CGImageRef CGImage = [context createCGImage:OriginalImage fromRect:(CGRect)];
UIImage *newImage = [UIImage imageWithCGImage:CGImage scale:1.0 orientation:UIImageOrientationLeft]

希望这会有所帮助。

相关问题