gpt4 book ai didi

iphone - 捕获卡在 DrawRect 方法中的 UIView 的 UIImage

转载 作者:行者123 更新时间:2023-11-28 18:06:28 25 4
gpt4 key购买 nike

我正在 try catch 我的 UIView 的图像,但是当我调用此方法时

- (UIImage *) imageWithView:(UIView *)view
{
UIGraphicsBeginImageContext(view.bounds.size);
[view.layer renderInContext:UIGraphicsGetCurrentContext()];

UIImage * img = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

return img;
}

我的应用程序进入我 View 的 DrawRect 方法并卡在这些行的循环中

[super drawRect:rect];
[curImage drawAtPoint:CGPointMake(0, 0)];
mid1 = midPoint(previousPoint1, previousPoint2);
mid2 = midPoint(currentPoint, previousPoint1);

context = UIGraphicsGetCurrentContext();

[self.layer renderInContext:context];

这是我的drawRect 方法

- (void)drawRect:(CGRect)rect
{

[super drawRect:rect];
[curImage drawAtPoint:CGPointMake(0, 0)];
mid1 = midPoint(previousPoint1, previousPoint2);
mid2 = midPoint(currentPoint, previousPoint1);

context = UIGraphicsGetCurrentContext();

[self.layer renderInContext:context];

CGContextMoveToPoint(context, mid1.x, mid1.y);
CGContextAddQuadCurveToPoint(context, previousPoint1.x, previousPoint1.y, mid2.x, mid2.y);

CGContextSetLineCap(context, kCGLineCapRound);
CGContextSetLineWidth(context, self.lineWidth);
CGContextSetStrokeColorWithColor(context, self.lineColor.CGColor);

CGContextStrokePath(context);
}

最佳答案

要捕获 UIView 图像,只需运行这些行并检查:

    CGRect screenRect = [[UIScreen mainScreen] bounds];
UIGraphicsBeginImageContextWithOptions(screenRect.size, NO, 0.0);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

关于iphone - 捕获卡在 DrawRect 方法中的 UIView 的 UIImage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14827338/

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