作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用来自 Apple 的众所周知的示例代码将相机缓冲区静止图像转换为 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?
谢谢
最佳答案
答案是它只影响进一步的修改,与缓冲区锁定无关。
正如您可以从这个答案模型中读到的那样,上下文是按时间应用的 Vertical flip of CGContext
关于ios - 从相机缓冲区 iOS 转换图像。使用 AVFoundation 捕获静止图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7551587/
有没有办法让天空/湖泊背景在你滚动时保持静止? Site 最佳答案 在 CSS 中: background-attachment: fixed http://www.w3schools.com/css
我正在研究 CSS 网格,我遇到了一些奇怪的事情。我想要 3 列:1 和 3 的宽度为 150px,其余为 2。我认为这应该是可能的,但这没有用: grid-template-columns: 150
我正在使用 -webkit-appearance 和 -moz-appearance 这样我就可以为我的单选按钮设置不同的样式。当我在 Chrome 中执行此操作时,我得到了我想要的: 当我为 Fir
我是一名优秀的程序员,十分优秀!