gpt4 book ai didi

ios - 使用 UIGraphicsGetImageFromCurrentImageContext 获取图像

转载 作者:行者123 更新时间:2023-11-29 11:10:51 28 4
gpt4 key购买 nike

我试图理解,UIgraphicsGetImageContext() 函数,根据我的理解,它是一个函数,它从当前位图上下文中获取图像,所以每当我在 Canvas 上绘制一些东西并调用此函数时,我都会绘制图像,但假设我不画任何东西,那么它也会提取一个空图像。所以我想了解一下,我们如何检查 Canvas (CGContext)何时为零。

下面是我试过的代码,但它不起作用

 UIGraphicsBeginImageContextWithOptions(self.bounds.size, NO,0.0);
[self.layer renderInContext:UIGraphicsGetCurrentContext()];
if(UIGraphicsGetCurrentContext() == nil)
{
NSLog(@"NIL");
}
else
{
m_curImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSLog(@"%@",m_curImage);
}

所以 friend 们,请告诉我如何得到这个,它会对我有所帮助

问候兰 git

最佳答案

UIGraphicsGetCurrentContext() 只有在图形上下文堆栈为空时才会返回 nil。在您的绘图代码中,您将始终有一个绘图上下文,因此它不会在此处返回 nil。 UIGraphicsBeginImageContextWithOptions 将新的上下文插入堆栈。

您不能使用 UIGraphicsGetCurrentContext() 来检测您是否在上下文中绘制了某些内容。

关于ios - 使用 UIGraphicsGetImageFromCurrentImageContext 获取图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11648528/

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