2015-09-29 79 views
0

我有我有image.However填充它CAShapeLayer,圖像顛倒了......colorWithPatternImage將圖像顛倒了嗎?

CAShapeLayer *shapeLayer = [CAShapeLayer layer]; 
    shapeLayer.path = [[self makeCircleAtLocation:location radius:100.0] CGPath]; 
    shapeLayer.strokeColor = [[UIColor colorWithRed:30/255.0f green:30/255.0f blue:30/255.0f alpha:1.0] CGColor]; 
    [self.dd.layer addSublayer:shapeLayer]; 

    shapeLayer.fillColor = [UIColor colorWithPatternImage:previewImageView.image].CGColor; //turned upside down inside the circle 
+0

你從哪裏得到圖像?這是照片嗎?如果是這樣,問題可能在照片元數據(方向)。 – rkyr

+0

它可以是一個照相機拍攝的圖片或從照片庫中選擇... –

回答

0

那麼問題可能是圖像元數據。它包含圖像的方向。我用這種方法擺脫它:

+ (UIImage *)normalizeImageOrientation:(UIImage *)image { 
    CGSize itemSize = CGSizeMake(image.size.width, image.size.height); 
    UIGraphicsBeginImageContext(itemSize); 
    CGRect imageRect = CGRectMake(0.0, 0.0, itemSize.width, itemSize.height); 
    [image drawInRect:imageRect]; 
    UIImage *resultImage = UIGraphicsGetImageFromCurrentImageContext(); 
    UIGraphicsEndImageContext(); 
    return resultImage; 
}