gpt4 book ai didi

ios - 如何在 ios 6.0 中使用 CGContextDrawImage 获取椭圆的边框

转载 作者:行者123 更新时间:2023-12-01 19:10:32 25 4
gpt4 key购买 nike

我使用以下带边框的代码绘制了一个椭圆。当我使用 CGContextDrawImage方法我没有得到边框,图像显示为椭圆形。否则我得到这个椭圆的边界线。其实我想得到椭圆形和边框的图像。我只有其中一个。我想两者兼得。

- (void)drawRect:(CGRect)rect
{
// Drawing code
context =UIGraphicsGetCurrentContext();
CGContextClearRect(context, self.bounds);
CGContextSetStrokeColorWithColor(context, [UIColor whiteColor].CGColor);
CGContextSetLineWidth(context, 5.0);
CGContextAddEllipseInRect(context, self.bounds);

CGContextClip(context);
CGContextStrokePath(context);
CGContextDrawImage(context, displayImageView.frame, displayImageView.image.CGImage);

}

已编辑:

我怎样才能解决我的问题,如下图所示
enter image description here

上面的 View 有带有白色边框的图像。我想要完全一样的。请告诉我任何一个。

最佳答案

CGContextClip还重置当前路径:

After determining the new clipping path, the function resets the context’s current path to an empty path.



做这个:
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextClearRect(context, self.bounds);
CGContextSetStrokeColorWithColor(context, [UIColor whiteColor].CGColor);
CGContextSetLineWidth(context, 5.0);
CGContextAddEllipseInRect(context, self.bounds);

CGContextClip(context);
CGContextDrawImage(context, displayImageView.frame, displayImageView.image.CGImage);
CGContextSetStrokeColorWithColor(context, [UIColor whiteColor].CGColor);
CGContextSetLineWidth(context, 5.0);
CGContextAddEllipseInRect(context, self.bounds);
CGContextStrokePath(context);

关于ios - 如何在 ios 6.0 中使用 CGContextDrawImage 获取椭圆的边框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16835807/

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