gpt4 book ai didi

ios - uiview仅渲染特定区域的xcode(不通过裁剪)

转载 作者:行者123 更新时间:2023-12-01 17:41:09 25 4
gpt4 key购买 nike

我现在正在尝试渲染uiview。我可以像这样正确渲染整个uiview。

    [toBeRecorded.layer renderInContext:UIGraphicsGetCurrentContext()];

但是,我想知道仅渲染这样的特定区域(不是通过裁剪..而是仅渲染特定区域)。我应该怎么做?

最佳答案

这是答案,我编写了此方法,并且效果很好:

+ (UIImage*) screenShotTheArea:(CGRect)area inView:(UIView*)view{

if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)])
UIGraphicsBeginImageContextWithOptions(CGSizeMake(area.size.width, area.size.height), NO, [UIScreen mainScreen].scale);
else
UIGraphicsBeginImageContext(view.bounds.size);

CGContextRef c = UIGraphicsGetCurrentContext();
CGContextTranslateCTM(c, -area.origin.x, -area.origin.y);
[view.layer renderInContext:c];
UIImage* thePrintScreen = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

return thePrintScreen;
}

关于ios - uiview仅渲染特定区域的xcode(不通过裁剪),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19383624/

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