【问题标题】:Interpolation issue after renderInContext:UIGraphicsGetCurrentContext(), iOSrenderInContext:UIGraphicsGetCurrentContext(), iOS 之后的插值问题
【发布时间】:2013-04-25 11:04:49
【问题描述】:

我有几个 UIVies 并排对接。视图完全覆盖了 superView。显示效果很好,但是在渲染时相邻的边缘是可见的,也就是说它们之间会出现一条线。由于视图在显示中看起来很完美,我想它一定是导致这种情况的视图像素的插值。

有人知道如何解决这个问题吗?

下图是渲染图。在设备或模拟器上,这些线将不可见。

渲染代码

-(void)renderImage {
    CGSize renderSize = CGSizeMake(masterView.frame.size.width, masterView.frame.size.height);
    UIGraphicsBeginImageContext(renderSize);
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSaveGState(context);
    CGContextConcatCTM(context, [[masterView layer] affineTransform]);
    [[masterView layer] renderInContext:UIGraphicsGetCurrentContext()];
    renderedImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    CGContextRestoreGState(context);
    UIImageWriteToSavedPhotosAlbum(renderedImage, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
    masterView.transform = CGAffineTransformIdentity;
}

【问题讨论】:

  • 您解决了这个问题吗?我在开发应用程序时遇到了同样的问题。

标签: ios uiview interpolation cglayer


【解决方案1】:

核心图形尝试消除视图的别名。你需要告诉它不要那样做。

考虑以下示例,它将自身(一个 UIView)呈现为一个没有抗锯齿的 UIImage:

UIGraphicsBeginImageContextWithOptions(self.bounds.size, YES, [[UIScreen mainScreen] scale]);
CGContextSetAllowsAntialiasing(UIGraphicsGetCurrentContext(), FALSE);
[self.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

【讨论】:

    【解决方案2】:

    尝试:

    UIGraphicsBeginImageContextWithOptions(renderSize, false, [[UIScreen mainScreen] scale]);
    

    代替:

    UIGraphicsBeginImageContext(renderSize);
    

    【讨论】:

    • 感谢您的建议!到目前为止,这并没有解决问题。关于您为何提出此建议的任何提示可能会有所帮助。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-03-05
    • 1970-01-01
    • 2019-06-02
    • 2017-09-04
    • 2014-09-22
    • 2012-04-11
    • 2015-02-10
    相关资源
    最近更新 更多