2011-11-16 66 views
0

這行代碼沒有效果。它不會改變圖像的方向。我究竟做錯了什麼?UIImage不改變方向

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

此答案對您有用:http://stackoverflow.com/questions/5427656/ios-uiimagepickercontroller-result-image-orientation-after-upload/5427890#5427890 它工作正常。 – kaspartus

+0

謝謝,它有幫助。 – kal21

回答

0

請參考下面這個方法的定義,確保你的CGImage是一個CGImageRef類。 imageWithCGImage:[image CGImage]

+(UIImage的*)imageWithCGImage:(CGImageRef)imageRef規模:(CGFloat的)規模取向:(UIImageOrientation)定向

以下三行一些初始化調用方法之前。

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] 

希望這會有所幫助。