2010-10-11 107 views
1

我想複製一個uiimage(最終我計劃模糊副本)。現在複製的圖像在模擬器中正確顯示,但在設備上運行時最終旋轉了90度。UIImage複製結束旋轉

我使用以下內容來創建ACOPY:

CGImageRef cgImage = [sourceImage CGImage]; 

//使從CG參考 UIImage的新的圖像* copyOfImage = [[UIImage的頁頭] initWithCGImage:cgImage];

源圖像來自UIImagePickerController。無論我從圖書館還是相機拿取相同的結果都會發生。

預先感謝任何幫助

回答

0

根據對UIImage的文件,imageOrientation屬性包含方位的圖像,其默認值爲UIImageOrientationUp。但是如果圖像有任何方向的EXIF數據,它將返回。 (CGImageRef)cgiImage和initWithCGImage:(CGImageRef)CGImage(在UIImage中)都默認爲UIImageOrientationUp方向,如果圖像/電影實際上是在例如圖像中拍攝的,那麼這可能是錯誤的。風景模式。

但是,如果您使用以上版本的方向以及通過sourceImage.imageOrientation它應該工作。

0

剛剛發生這種情況,特別是模糊使用,我不會建議使用完整的圖像。

我發現這個過程太慢了,而且由於原始圖像模糊不清,您最好先製作一個小圖像,然後將其縮放並將其模糊化。

我沒有測試過,因爲它與我原來的項目有點不同。

此代碼使用UIImage + Resize進行調整大小。

//Creates an autoreleased representing the current screen view 
-(UIImage *)currentBlurredImage:(UIImage *)anImage{ 

CGImageRef imageRef = CGImageCreateWithImageInRect([anImage CGImage], bounds); 
UIImage *coppiedImage = [UIImage imageWithCGImage:imageRef scale:1.0 orientation:anImage.imageOrientation]; 

coppiedImage = [viewImage resizedImage:CGSizeMake(120, 80) interpolationQuality:kCGInterpolationLow]; 
coppiedImage = [viewImage blurredCopyUsingGuassFactor:4 andPixelRadius:4]; 
return coppiedImage ; 

}

模糊處理與代碼完成從這裏http://iphonedevelopment.blogspot.com/2010/08/uiimage-blur.html(信貸,其應有的!)。但是,我清理它並處理了一堆內存和其他問題。

http://pastebin.com/MaHvvdim