Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/116.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从相机缓冲区iOS转换图像。使用AVFoundation捕获静止图像_Ios_Camera_Uiimage_Buffer_Quartz Graphics - Fatal编程技术网

从相机缓冲区iOS转换图像。使用AVFoundation捕获静止图像

从相机缓冲区iOS转换图像。使用AVFoundation捕获静止图像,ios,camera,uiimage,buffer,quartz-graphics,Ios,Camera,Uiimage,Buffer,Quartz Graphics,我正在使用苹果公司的这段著名的示例代码将相机缓冲区的静态图像转换为UIImage -(UIImage*) getUIImageFromBuffer:(CMSampleBufferRef) imageSampleBuffer{ // Get a CMSampleBuffer's Core Video image buffer for the media data CVImageBufferRef imageBuffer = CMSampleBufferGetImageBuffer(imageSa


我正在使用苹果公司的这段著名的示例代码将相机缓冲区的静态图像转换为UIImage

-(UIImage*) getUIImageFromBuffer:(CMSampleBufferRef) imageSampleBuffer{

// Get a CMSampleBuffer's Core Video image buffer for the media data
CVImageBufferRef imageBuffer = CMSampleBufferGetImageBuffer(imageSampleBuffer); 

if (imageBuffer==NULL) {
    NSLog(@"No buffer");
}

// Lock the base address of the pixel buffer 
if((CVPixelBufferLockBaseAddress(imageBuffer, 0))==kCVReturnSuccess){
    NSLog(@"Buffer locked successfully");
} 

void *baseAddress = CVPixelBufferGetBaseAddress(imageBuffer); 

// Get the number of bytes per row for the pixel buffer
size_t bytesPerRow = CVPixelBufferGetBytesPerRow(imageBuffer); 
NSLog(@"bytes per row %zu",bytesPerRow );
// Get the pixel buffer width and height
size_t width = CVPixelBufferGetWidth(imageBuffer); 
NSLog(@"width %zu",width);

size_t height = CVPixelBufferGetHeight(imageBuffer); 
NSLog(@"height %zu",height);

// Create a device-dependent RGB color space
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); 

// Create a bitmap graphics context with the sample buffer data
CGContextRef context = CGBitmapContextCreate(baseAddress, width, height, 8, 
bytesPerRow, colorSpace, kCGBitmapByteOrder32Little | kCGImageAlphaPremultipliedFirst); 

// Create a Quartz image from the pixel data in the bitmap graphics context
CGImageRef quartzImage = CGBitmapContextCreateImage(context); 

// Free up the context and color space
CGContextRelease(context); 
CGColorSpaceRelease(colorSpace);

// Create an image object from the Quartz image
UIImage *image= [UIImage imageWithCGImage:quartzImage scale:SCALE_IMAGE_RATIO orientation:UIImageOrientationRight];

// Release the Quartz image
CGImageRelease(quartzImage);

// Unlock the pixel buffer
CVPixelBufferUnlockBaseAddress(imageBuffer,0);


return (image );}
问题是,您获得的图像通常会旋转90°。使用方法+imageWithCGImage:scale:orientation我可以旋转它,但在使用此方法之前,我尝试使用CTM函数旋转和缩放图像,然后将其传递给UIImage。问题是CTM转换不会影响图像。
我在问自己为什么。。。那是因为我锁定了缓冲区吗?或者因为创建的上下文中包含图像,所以更改只会影响进一步的修改?

谢谢

答案是它只影响进一步的修改,而不涉及缓冲区锁定。
正如你可以从这个答案中读到的,mod的上下文是按时间应用的