gpt4 book ai didi

ios - CIContext 呈现 : toCVPixelBuffer: bounds: colorSpace: function does not work for images with alpha channel

转载 作者:行者123 更新时间:2023-11-29 11:39:07 48 4
gpt4 key购买 nike

我正在尝试在使用 AVFoundation 的 AVCaptureVideoDataOutput 录制的视频上添加水印/ Logo 。我遇到的问题是 UIImage 的透明部分在写入视频后变为黑色。我是什么我做错了吗?

CVPixelBufferRef pixelBuffer = CMSampleBufferGetImageBuffer(buffer);

....

....

CIImage *image = [[CIImage alloc] initWithData:logoData]; 
CVPixelBufferLockBaseAddress( pixelBuffer, 0 );

CIContext *ciContext = [CIContext contextWithOptions:nil];

CGColorSpaceRef cSpace = CGColorSpaceCreateDeviceRGB();

[ciContext render:image toCVPixelBuffer:pixelBuffer bounds:CGRectMake(image.extent.origin.x, image.extent.origin.y - 2, image.extent.size.width, image.extent.size.height) colorSpace:cSpace];


CVPixelBufferUnlockBaseAddress(pixelBuffer, 0);
CGColorSpaceRelease(cSpace);

最佳答案

您可以合成将保留透明度的图像并将其渲染到像素缓冲区。例如:

    CVPixelBufferRef pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);
CIImage *cameraImage = [[CIImage alloc] initWithCVPixelBuffer:pixelBuffer];
CGColorSpaceRef cSpace = CGColorSpaceCreateDeviceRGB();
cameraImage = [self.logoImage imageByCompositingOverImage:cameraImage];
[self.context render:cameraImage toCVPixelBuffer:pixelBuffer bounds:cameraImage.extent colorSpace:cSpace];

CVPixelBufferUnlockBaseAddress(pixelBuffer, 0);
CGColorSpaceRelease(cSpace);

关于ios - CIContext 呈现 : toCVPixelBuffer: bounds: colorSpace: function does not work for images with alpha channel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47576163/

48 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com