2013-12-18 91 views
1

我在UIImage上應用過濾器,但轉換後,它顯示爲側面。以下是我的代碼。UIImage將其從CIImage轉換後側身

CIImage *ciImage = [[CIImage alloc] initWithImage:self.imgToProcess]; 

CIFilter *filter = [CIFilter filterWithName:@"CIPhotoEffectChrome" 
               keysAndValues:kCIInputImageKey, ciImage, nil]; 
[filter setDefaults]; 

CIContext *context = [CIContext contextWithOptions:nil]; 
CIImage *outputImage = [filter outputImage]; 

CGImageRef cgImage = [context createCGImage:outputImage fromRect:[outputImage extent]]; 

UIImage *newImage = [[UIImage alloc]initWithCIImage:outputImage]; 

它在newImage和尺寸中成功呈現,但圖像是副作用。上述代碼中是否有導致方向改變的地方?

回答

0

是的,你可以考慮設置圖像方向,以確保一個初始化UIImage與方法:

- (id)initWithCGImage:(CGImageRef)imageRef scale:(CGFloat)scale orientation:(UIImageOrientation)orientation 

而且你有幾個像取向:

typedef enum { 
    UIImageOrientationUp, 
    UIImageOrientationDown, // 180 deg rotation 
    UIImageOrientationLeft, // 90 deg CW 
    UIImageOrientationRight, // 90 deg CCW 
    UIImageOrientationUpMirrored, // as above but image mirrored along 
    // other axis. horizontal flip 
    UIImageOrientationDownMirrored, // horizontal flip 
    UIImageOrientationLeftMirrored, // vertical flip 
    UIImageOrientationRightMirrored, // vertical flip 
} UIImageOrientation; 

Up是默認 - 所以試着旋轉它。

+0

我們正在談論CIIimage – tspentzas

1

在應用過濾器之前將圖像縮放到正確的方向。

請點擊此鏈接:https://stackoverflow.com/q/538064/871102

相反的:

CIImage *ciImage = [[CIImage alloc] initWithImage:self.imgToProcess]; 

寫:

UIImage *properOrientedImage = [self scaleAndRotateImage:self.imgToProcess]; 

CIImage *ciImage = [[CIImage alloc] initWithImage:properOrientedImage.CGImage];