gpt4 book ai didi

ios - 将 UIImage 数组导出到视频 - 蓝色结果

转载 作者:行者123 更新时间:2023-11-29 10:23:53 26 4
gpt4 key购买 nike

我正在使用 AVAssetWriterAVAssetWriterInputPixelBufferAdaptorUIImage 数组制作视频。结果影片播放正常,但全都是蓝色调。我知道像素格式不正确,但还不足以解决问题。

AVAssetWriterInputPixelBufferAdaptor 代码:

NSDictionary *sourcePixelBufferAttributesDictionary = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:kCVPixelFormatType_32ARGB], kCVPixelBufferPixelFormatTypeKey, nil];

AVAssetWriterInputPixelBufferAdaptor *adaptor = [AVAssetWriterInputPixelBufferAdaptor assetWriterInputPixelBufferAdaptorWithAssetWriterInput:writerInput
sourcePixelBufferAttributes:sourcePixelBufferAttributesDictionary];

CGImageRef生成CVPixelBufferRef

+ (CVPixelBufferRef)pixelBufferFromCGImage:(CGImageRef)image
{
CGSize frameSize = CGSizeMake(CGImageGetWidth(image), CGImageGetHeight(image));
NSDictionary *options = @{
(__bridge NSString *)kCVPixelBufferCGImageCompatibilityKey: @(NO),
(__bridge NSString *)kCVPixelBufferCGBitmapContextCompatibilityKey: @(NO)
};
CVPixelBufferRef pixelBuffer;
CVReturn status = CVPixelBufferCreate(kCFAllocatorDefault, frameSize.width,
frameSize.height, kCVPixelFormatType_32ARGB, (__bridge CFDictionaryRef) options,
&pixelBuffer);
if (status != kCVReturnSuccess) {
return NULL;
}

CVPixelBufferLockBaseAddress(pixelBuffer, 0);
void *data = CVPixelBufferGetBaseAddress(pixelBuffer);
CGColorSpaceRef rgbColorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef context = CGBitmapContextCreate(data, frameSize.width, frameSize.height,
8, CVPixelBufferGetBytesPerRow(pixelBuffer), rgbColorSpace,
(CGBitmapInfo) kCGImageAlphaNoneSkipLast);
CGContextDrawImage(context, CGRectMake(0, 0, CGImageGetWidth(image),
CGImageGetHeight(image)), image);
CGColorSpaceRelease(rgbColorSpace);
CGContextRelease(context);
CVPixelBufferUnlockBaseAddress(pixelBuffer, 0);

return pixelBuffer;
}

有什么建议吗?

最佳答案

调用 CGBitmapContextCreate 时,您应该传递 kCGImageAlphaNoneSkipFirst 而不是 kCGImageAlphaNoneSkipLast

这是因为您的位图布局为 alpha 然后颜色,而不是颜色然后 alpha。

之所以会出现蓝色调,是因为您将 ARG 视为 RGB。 A (alpha) 为零,因此您的图像中没有红色。一般来说,从图像中去除所有红色会给您带来蓝绿色调。

关于ios - 将 UIImage 数组导出到视频 - 蓝色结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33423775/

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