如何在 Xamarin.iOS 中将 BGRA 转换为 RGBA? [英] How to convert BGRA to RGBA in Xamarin.iOS?
问题描述
我正在使用 AVFoundation 从相机和显示器到 UrhoSharp 获取实时帧.
I am using AVFoundation to get real-time frames from camera and display to the UrhoSharp.
但是,似乎 UrhoSharp 中的 Texture2D 不支持来自 AVVideoOutput 的 BGRA.所以我想把CVPixelBuffer"转换成RGB格式.
However, seems the Texture2D in UrhoSharp is not support the BGRA from AVVideoOutput. So I want to convert the "CVPixelBuffer" to RGB format.
我发现 vImage 中有一个 APIvImagePermuteChannels_ARGB8888",可以将 BGRA 转换为 ARGB,但 Xamarin 不提供.
I found there is an API in vImage "vImagePermuteChannels_ARGB8888", which can convert the BGRA to ARGB but this is not provided by Xamarin.
那么如何解决这个问题?
So how to solve this problem?
推荐答案
Accelerate.framework
由 C
函数组成,所以:
The Accelerate.framework
consists of C
functions, so:
vImage_Error vImagePermuteChannels_ARGB8888( const vImage_Buffer *src,
const vImage_Buffer *dest,
const uint8_t permuteMap[4],
vImage_Flags flags ) VIMAGE_NON_NULL(1,2,3) __OSX_AVAILABLE_STARTING( __MAC_10_4, __IPHONE_5_0 );
可以通过以下方式使用:
Can be used via:
[DllImport("/System/Library/Frameworks/Accelerate.framework/Frameworks/vImage.framework/vImage")]
public unsafe static extern vImageError vImagePermuteChannels_ARGB8888(ref vImageBuffer src, ref vImageBuffer dest, [MarshalAs(UnmanagedType.LPArray)]uint[] permuteMap, vImageFlags flags);
参考:https://developer.apple.com/documentation/accelerate/1533241-vimagepermutechannels_argb8888
参考:Conversion.h
/Applications/Xcode9.1.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/Accelerate.framework/Frameworks/vImage.framework/Headers
这篇关于如何在 Xamarin.iOS 中将 BGRA 转换为 RGBA?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!