我在我的iPhone应用程序中使用CGBitmapContextCreateImage时遇到问题。CGBitmapContextCreateImage - vm_copy失败 - iPhone SDK
我使用AV Foundation框架使用这种方法抢相机帧:
- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection {
CVImageBufferRef imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);
CVPixelBufferLockBaseAddress(imageBuffer,0);
uint8_t *baseAddress = (uint8_t *)CVPixelBufferGetBaseAddress(imageBuffer);
size_t bytesPerRow = CVPixelBufferGetBytesPerRow(imageBuffer);
size_t width = CVPixelBufferGetWidth(imageBuffer);
size_t height = CVPixelBufferGetHeight(imageBuffer);
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef newContext = CGBitmapContextCreate(baseAddress, width, height, 8, bytesPerRow, colorSpace, kCGBitmapByteOrder32Little | kCGImageAlphaPremultipliedFirst);
CGImageRef newImage = CGBitmapContextCreateImage(newContext);
CVPixelBufferUnlockBaseAddress(imageBuffer,0);
CGContextRelease(newContext);
CGColorSpaceRelease(colorSpace);
UIImage *image= [UIImage imageWithCGImage:newImage scale:1.0 orientation:UIImageOrientationRight];
self.imageView.image = image;
CGImageRelease(newImage);
}
但是,我看到一个错误在调试控制台作为其运行:
<Error>: CGDataProviderCreateWithCopyOfData: vm_copy failed: status 2.
有没有人看到这个?通过评论行我已经缩小了问题线:
CGImageRef newImage = CGBitmapContextCreateImage(newContext);
但我不知道如何摆脱它。在功能上,它效果很好。很显然,CGImage正在创建,但我需要知道是什么导致了错误,所以它不会影响其他部分。
非常感谢。任何帮助/建议都会很棒! Brett
我有相同的问题相同的代码。但问题只出现在iOS 4上的iPhone 3G设备上。它在iPhone 4或iPhone 3GS上没有任何问题。你能证实这一点吗? – 2010-08-06 01:26:19
我可以确认我下面介绍的修复方法确实有效。我在iOS 4上获得了vm_copy消息。 – mvds 2010-08-12 13:06:06