gpt4 book ai didi

ios - renderInContext 翻转 colorWithPatternImage 的原点

转载 作者:可可西里 更新时间:2023-11-01 03:30:11 24 4
gpt4 key购买 nike

我有 UIViewbackgroundColor 设置为 colorWithPatternImage。正如预期的那样,背景图像是从左角开始绘制的。

当我在该 View 上执行 renderInContext 时出现问题:背景图像是从 bottom 左角开始绘制的。其他一切似乎都很好。

这是源图像和目标图像:

enter image description here

代码如下:

// here is the layer to be rendered into an image
UIView *src = [[UIView alloc] initWithFrame:(CGRect){{0, 0}, {100, 100}}];
src.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"background.png"]];
[self.view addSubview:src];

// here we'll display the image
UIImageView *dest = [[UIImageView alloc] initWithFrame:(CGRect){{110, 0}, src.bounds.size}];
[self.view addSubview:dest];

// render `src` to an image in `dest`
UIGraphicsBeginImageContext(src.bounds.size);
CGContextRef context = UIGraphicsGetCurrentContext();
[src.layer renderInContext:context];
dest.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

有没有办法像在 src View 中那样使图像在正确的方向平铺?

最佳答案

我通过调用高度为 modf(viewHeight, patternHeight) 的 CGContextSetPatternPhase 设法解决了这个问题

关于ios - renderInContext 翻转 colorWithPatternImage 的原点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13445850/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com