【问题标题】:colorWithPatternImage turns image upside down?colorWithPatternImage 将图像颠倒?
【发布时间】:2015-12-26 20:52:52
【问题描述】:

我有一个 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

【问题讨论】:

  • 你从哪里得到的图像?是照片吗?如果是这样,问题可能出在照片元数据(方向)中。
  • 可以是用相机拍的照片,也可以是从照片库中选择的...

标签: ios objective-c


【解决方案1】:

所以问题可能出在图像元数据中。它包含图像方向。我用这个方法摆脱它:

+ (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;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-11-21
    • 2017-03-20
    • 2022-08-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-29
    • 2012-02-19
    相关资源
    最近更新 更多