gpt4 book ai didi

ios - 无效上下文 0x0 CGContextDrawImage

转载 作者:行者123 更新时间:2023-11-29 11:00:15 25 4
gpt4 key购买 nike

在运行了以下代码块之后,我得到了 CGContextDrawImage 的无效上下文 0x0。此代码位于 UIViewController 中的用户定义方法中。我本质上是通过使用 AVFoundation 拍摄静止图像来捕捉图像,并拍摄该图像以读取像素十六进制数据值。下面是我写的代码:

AVCaptureConnection *videoConnection = nil;
for (AVCaptureConnection *connection in stillImageOutput.connections)
{
for (AVCaptureInputPort *port in [connection inputPorts])
{
if ([[port mediaType] isEqual:AVMediaTypeVideo] )
{
videoConnection = connection;
break;
}
}
if (videoConnection) { break; }
}
[stillImageOutput captureStillImageAsynchronouslyFromConnection:videoConnection completionHandler: ^(CMSampleBufferRef imageSampleBuffer, NSError *error)
{
CFDictionaryRef exifAttachments = CMGetAttachment( imageSampleBuffer, kCGImagePropertyExifDictionary, NULL);
NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageSampleBuffer];
image2 = [[UIImage alloc] initWithData:imageData];
}];

CGImageRef imageRef = [image CGImage];
CGContextRef context = CGBitmapContextCreate(rawData, width, height,bitsPerComponent,bytesPerRow, colorSpace,kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);
CGColorSpaceRelease(colorSpace);
CGContextDrawImage(context, CGRectMake(0, 0, width, height), imageRef);

为什么我得到 CGContextDrawImage 的无效上下文 0x0?

最佳答案

CGBitmapContextCreate如果无法创建请求的上下文,则返回 NULLCGContextDrawImage 本质上是在提示 contextNULL

关于ios - 无效上下文 0x0 CGContextDrawImage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16242936/

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