colorWithPatternImage将图像颠倒?

时间:2015-09-29 11:36:21

标签: ios objective-c

我有一个CAShapeLayer,我用图像填充它。但是,图像正在翻转...

 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

1 个答案:

答案 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;
}