gpt4 book ai didi

ios4 - CGContext & CGBitmapContextCreateImage 错误,如何解决?

转载 作者:行者123 更新时间:2023-12-03 18:20:55 24 4
gpt4 key购买 nike

我已经在这里呆了几个小时了,甚至不知道如何调试这个错误。也许有一位 SO 专家知道发生了什么。

- (void) prepareSubset {

CGSize size = [image size];

float scale = fminf(1.0f, fmaxf(SUBSET_SIZE / cropRect.size.width, SUBSET_SIZE / cropRect.size.height));
CGPoint offset = CGPointMake(-cropRect.origin.x, -cropRect.origin.y);

subsetWidth = cropRect.size.width * scale;
subsetHeight = cropRect.size.height * scale;

subsetBytesPerRow = ((subsetWidth + 0xf) >> 4) << 4;
subsetData = (unsigned char *)malloc(subsetBytesPerRow * subsetHeight);

CGColorSpaceRef grayColorSpace = CGColorSpaceCreateDeviceGray();

CGContextRef ctx = CGBitmapContextCreate(subsetData, subsetWidth, subsetHeight, 8, subsetBytesPerRow, grayColorSpace, kCGImageAlphaNone);
CGColorSpaceRelease(grayColorSpace);
CGContextSetInterpolationQuality(ctx, kCGInterpolationNone);
CGContextSetAllowsAntialiasing(ctx, false);

CGContextTranslateCTM(ctx, 0.0, subsetHeight);
CGContextScaleCTM(ctx, 1.0, -1.0);

UIGraphicsPushContext(ctx);
CGRect rect = CGRectMake(offset.x * scale, offset.y * scale, scale * size.width, scale * size.height);
[image drawInRect:rect];
UIGraphicsPopContext();

CGContextFlush(ctx);

CGImageRef subsetImageRef = CGBitmapContextCreateImage(ctx);

self.subsetImage = [UIImage imageWithCGImage:subsetImageRef];
CGImageRelease(subsetImageRef);

CGContextRelease(ctx);

}

这些是我调用此方法后出现的错误
<Error>: CGContextSetInterpolationQuality: invalid context 0x0
<Error>: CGContextSetAllowsAntialiasing: invalid context 0x0
<Error>: CGContextTranslateCTM: invalid context 0x0
<Error>: CGContextScaleCTM: invalid context 0x0
<Error>: CGContextSaveGState: invalid context 0x0
<Error>: CGContextSetBlendMode: invalid context 0x0
<Error>: CGContextSetAlpha: invalid context 0x0
<Error>: CGContextTranslateCTM: invalid context 0x0
<Error>: CGContextScaleCTM: invalid context 0x0
<Error>: CGContextDrawImage: invalid context 0x0
<Error>: CGContextRestoreGState: invalid context 0x0
<Error>: CGContextFlush: invalid context 0x0
<Error>: CGBitmapContextCreateImage: invalid context 0x0

谁能告诉我这是怎么回事?提前致谢。

最佳答案

如果创建上下文时出错,则 CGBitmapContextCreate 返回 NULL,因此这是“无效上下文 0x0”消息的最终原因——由于错误,上下文字面上设置为 0x0 (NULL)。我不知道为什么 CGBitmapContextCreate 有错误,但这就是您应该开始调试的地方。检查所有输入参数,并将您对 CGBitmapContextCreate 的使用与 Apple 的示例之一(例如 this one)进行比较。 .

关于ios4 - CGContext & CGBitmapContextCreateImage 错误,如何解决?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3571053/

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