我的类被设置为sampleBufferDelegate并接收CMSamplebufferRefs.我已经将一些效果应用于CMSampleBufferRefs CVPixelBuffer并将其传递回AVAssetWriter.
左上角的徽标使用透明PNG传送.
我遇到的问题是,一旦写入视频,UIImage的透明部分就是黑色.
任何人都知道我做错了什么或者可能会忘记?
代码片段如下:
//somewhere in the init of the class; _eaglContext = [[EAGLContext alloc] initWithAPI:kEAglrenderingAPIOpenGLES2];_ciContext = [CIContext contextWithEAGLContext:_eaglContext options: @{ kCIContextWorkingcolorSpace : [NSNull null] }];//samplebufferdelegate method:- (voID) captureOutput:(AVCaptureOutput *)captureOutput dIDOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection { CVPixelBufferRef pixelBuffer = CMSampleBufferGetimageBuffer(sampleBuffer); CVPixelBufferLockBaseAddress(pixelBuffer,0);....UIImage *logoImage = [UIImage imagenamed:@"logo.png"];CIImage *renderImage = [[CIImage alloc] initWithCGImage:logoImage.CGImage];CGcolorSpaceRef cSpace = CGcolorSpaceCreateDeviceRGB();[_ciContext render:renderImage toCVPixelBuffer:pixelBuffer bounds: [renderImage extent] colorSpace:cSpace];CVPixelBufferUnlockBaseAddress(pixelBuffer,0);CGcolorSpaceRelease(cSpace);....}
看起来CIContext没有绘制CIImages Alpha.
有任何想法吗?
看起来在GPU上呈现的任何内容都会写入视频,最终会在视频中形成黑洞.
相反,我删除了上面的代码,创建了一个CGContextRef,就像编辑图像时一样,并绘制了上下文.
码:
....CVPixelBufferLockBaseAddress( pixelBuffer,0 );CGContextRef context = CGBitmapContextCreate(CVPixelBufferGetBaseAddress(pixelBuffer),CVPixelBufferGetWIDth(pixelBuffer),CVPixelBufferGetHeight(pixelBuffer),8,CVPixelBufferGetBytesPerRow(pixelBuffer),CGcolorSpaceCreateDeviceRGB(),(CGBitmAPInfo) kCGBitmapByteOrder32little | kCGImageAlphaPremultiplIEdFirst);CGRect renderBounds = ...CGContextDrawImage(context,renderBounds,[overlayImage CGImage]);CVPixelBufferUnlockBaseAddress(pixelBuffer,0);CGcolorSpaceRelease(cSpace);....
当然,不再需要全局EAGLContext和CIContext.
总结以上是内存溢出为你收集整理的ios – 核心图像 – 在CMSampleBufferRef上渲染透明图像会导致其周围出现黑框全部内容,希望文章能够帮你解决ios – 核心图像 – 在CMSampleBufferRef上渲染透明图像会导致其周围出现黑框所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)