AVCaptureSession returning blank image on iPhone 3G only

≡放荡痞女 提交于 2019-12-04 11:44:58
John Carter

something funky in the API so the work around that I'm using is:

//void *baseAddress = CVPixelBufferGetBaseAddress(imageBuffer);     
size_t bytesPerRow = CVPixelBufferGetBytesPerRow(imageBuffer);     
size_t width = CVPixelBufferGetWidth(imageBuffer);     
size_t height = CVPixelBufferGetHeight(imageBuffer);     

// vm_copy fails on older model phones...    
//    
uint8_t *baseAddress = malloc( bytesPerRow * height );    
memcpy( baseAddress, CVPixelBufferGetBaseAddress(imageBuffer), bytesPerRow * height );

CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();     

// NO ALPHA CHANNEL ON OLDER MODELS    
// CGContextRef context = CGBitmapContextCreate(baseAddress, width, height, 8, bytesPerRow, colorSpace, kCGBitmapByteOrder32Little | kCGImageAlphaPremultipliedFirst);     
CGContextRef context = CGBitmapContextCreate(baseAddress, width, height, 8, bytesPerRow, colorSpace, kCGBitmapByteOrder32Little | kCGImageAlphaNoneSkipFirst);     
CGImageRef quartzImage = CGBitmapContextCreateImage(context);     

CVPixelBufferUnlockBaseAddress(imageBuffer,0);    
CGContextRelease(context);     
CGColorSpaceRelease(colorSpace);    
free( baseAddress );

UIImage *image = [UIImage imageWithCGImage:quartzImage];    
CGImageRelease(quartzImage);

return image;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!