gpt4 book ai didi

ios - <错误> : CGBitmapContextCreateImage: invalid context 0x0

转载 作者:可可西里 更新时间:2023-11-01 05:05:50 24 4
gpt4 key购买 nike

我有一个使用 CGContextDrawImage 函数组合两个图像的应用程序。这是我的问题。在 iphone 5 的 ios 模拟器中,只有一个图像出现,而另一个没有出现,而在 iphone 3 的 iphone 模拟器中,显示这些图像没有问题,我也没有任何问题。顺便说一句,这是 Xcode 给我的错误列表。

//错误

:CGContextRotateCTM:无效上下文 0x0。这是一个严重的错误。此应用程序或其使用的库正在使用无效的上下文,从而导致系统稳定性和可靠性的整体下降。此通知是礼貌的:请解决此问题。它将成为即将到来的更新中的 fatal error 。

: CGContextDrawImage: 无效上下文 0x0。这是一个严重的错误。此应用程序或其使用的库正在使用无效的上下文,从而导致系统稳定性和可靠性的整体下降。此通知是礼貌的:请解决此问题。它将成为即将到来的更新中的 fatal error 。

:CGBitmapContextCreateImage:无效上下文 0x0。这是一个严重的错误。此应用程序或其使用的库正在使用无效的上下文,从而导致系统稳定性和可靠性的整体下降。此通知是礼貌的:请解决此问题。它将成为即将到来的更新中的 fatal error 。

谁能帮帮我?提前致谢。

这是我的示例代码:

CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGRect xFirstFrame = m_pUserImgView.frame;
int nWidth = xFirstFrame.size.width;
int nHeight = xFirstFrame.size.height;
CGFloat rScaleX;
CGPoint xOrgCenter;
UIImage* pJustinImage = m_pJustinImgView.image;
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
xOrgCenter = CGPointMake(384, 512);
}
else
if ([self appDelegate].isiPhone5 == YES)
{
xOrgCenter = CGPointMake(160, 284);
}
else
{
xOrgCenter = CGPointMake(160, 240);
}
CGContextRef buf_context = CGBitmapContextCreate(nil, nWidth, nHeight, 8, nWidth * 4, colorSpace, kCGImageAlphaPremultipliedLast);
CGColorSpaceRelease(colorSpace);
CGRect rect = CGRectMake(0,0, nWidth, nHeight);
CGRect xSecRect = m_pJustinImgView.bounds;
UIGraphicsPushContext(buf_context);
CGContextClearRect(buf_context, rect);
CGContextDrawImage(buf_context, rect, m_pUserImgView.image.CGImage);
//Transform Context
CGAffineTransform pTransform = m_pJustinImgView.transform;
CGAffineTransform xRealTrans = CGAffineTransformMake(pTransform.a, pTransform.b, pTransform.c, pTransform.d, pTransform.tx, -pTransform.ty);

CGPoint xOrgPoint = CGPointMake(xOrgCenter.x + pTransform.tx, xOrgCenter.y - pTransform.ty);
CGFloat rDegree = [self CalcRotateAngle:xRealTrans];
CGContextTranslateCTM(buf_context, xOrgPoint.x, xOrgPoint.y);
CGContextRotateCTM(buf_context, -rDegree);
rScaleX = sqrtf(pTransform.a * pTransform.a + pTransform.c * pTransform.c);
CGContextDrawImage(buf_context, CGRectMake(- xSecRect.size.width * rScaleX/2, - xSecRect.size.height * rScaleX/2, xSecRect.size.width * rScaleX , xSecRect.size.height * rScaleX), pJustinImage.CGImage);
UIGraphicsPopContext();

CGImageRef image = CGBitmapContextCreateImage(buf_context);
CGContextRelease(buf_context);

UIImage* pCombImage = [[UIImage alloc] initWithCGImage:image];
CGImageRelease(image);

return pCombImage;

//加载图片的代码

CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGRect xFirstFrame = m_pBackImageView.frame;



int nWidth = xFirstFrame.size.width;
int nHeight = xFirstFrame.size.height;
CGFloat rScaleX;
CGPoint xOrgCenter;

if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
xOrgCenter = CGPointMake(384, 512);
}
else
{
if ([self appDelegate].isiPhone5 == YES)
{
xOrgCenter = CGPointMake(160, 284);
}
else
{
xOrgCenter = CGPointMake(160, 240);
}
}

CGContextRef buf_context = CGBitmapContextCreate(nil, nWidth, nHeight, 8, nWidth * 4, colorSpace, kCGImageAlphaPremultipliedLast);
CGColorSpaceRelease(colorSpace);
CGRect rect = CGRectMake(0,0, nWidth, nHeight);
CGRect xSecRect = m_pUserImgView.bounds;
UIGraphicsPushContext(buf_context);
CGContextClearRect(buf_context, rect);
CGContextDrawImage(buf_context, rect, m_pBackImageView.image.CGImage);
//Transform Context
CGAffineTransform pTransform = m_pUserImgView.transform;
CGAffineTransform xRealTrans = CGAffineTransformMake(pTransform.a, pTransform.b, pTransform.c, pTransform.d, pTransform.tx, -pTransform.ty);

CGPoint xOrgPoint = CGPointMake(xOrgCenter.x + pTransform.tx, xOrgCenter.y - pTransform.ty);
CGFloat rDegree = [self CalcRotateAngle:xRealTrans];
CGContextTranslateCTM(buf_context, xOrgPoint.x, xOrgPoint.y);
CGContextRotateCTM(buf_context, -rDegree);
rScaleX = sqrtf(pTransform.a * pTransform.a + pTransform.c * pTransform.c);
CGContextDrawImage(buf_context, CGRectMake(- xSecRect.size.width * rScaleX/2, - xSecRect.size.height * rScaleX/2, xSecRect.size.width * rScaleX , xSecRect.size.height * rScaleX), m_pUserImgView.m_pViewImage.CGImage);
UIGraphicsPopContext();

CGImageRef image = CGBitmapContextCreateImage(buf_context);
CGContextRelease(buf_context);

UIImage* pCombImage = [[UIImage alloc] initWithCGImage:image];
CGImageRelease(image);

return pCombImage;

最佳答案

试试这个:在 xcode 中将符号断点添加到 CGPostError。 (添加符号断点,并在 Symbol 字段类型 CGPostError)

当错误发生时,调试器将停止代码执行,您可以检查方法调用堆栈和检查参数。寻找 0 大小的表面。某些参数的大小将为 0。

关于ios - <错误> : CGBitmapContextCreateImage: invalid context 0x0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19619231/

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