gpt4 book ai didi

iphone - 如何使用 CGContextDrawTiledImage 平铺图像?

转载 作者:行者123 更新时间:2023-12-03 18:33:22 24 4
gpt4 key购买 nike

我希望能够像 UIImageView 这样的 UI 对象并在其中平铺图像。

我已经能够使用 CGContextDrawTiledImage 来更新主窗口中的背景,但不能更新 ImageView 。如果我修改 MainView 类中的 drawRect 函数,我就可以做到这一点。

我觉得我已经很接近了,但仍然缺少一些东西。有人能指出我正确的方向吗?

- (void)drawRect:(CGRect)rect {

CGImageRef image = CGImageRetain(currentImage.CGImage);

CGRect imageRect;
imageRect.origin = CGPointMake(160, 240);
imageRect.size = CGSizeMake(320.0, 480.0);

CGContextRef uiContext = UIGraphicsGetCurrentContext();

CGContextClipToRect(uiContext, CGRectMake(0.0, 0.0, rect.size.width, rect.size.height));

CGContextDrawTiledImage(uiContext, imageRect, image);

}

最佳答案

如果您只想在 View 中平铺图像,请将其更改为普通 UIView 并使用 UIColor initWithPatternImage 平铺背景:

backgroundView.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageWithContentsOfFile:[self bundlePath:@"some_tile_image.png" inDirectory:@"tiles"]]];

关于iphone - 如何使用 CGContextDrawTiledImage 平铺图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/679925/

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