How to convert BGRA to RGBA in Xamarin.iOS?

 ̄綄美尐妖づ 提交于 2019-12-24 07:29:55

问题


I am using AVFoundation to get real-time frames from camera and display to the UrhoSharp.

However, seems the Texture2D in UrhoSharp is not support the BGRA from AVVideoOutput. So I want to convert the "CVPixelBuffer" to RGB format.

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?


回答1:


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);

Ref: https://developer.apple.com/documentation/accelerate/1533241-vimagepermutechannels_argb8888

Ref: Conversion.h

  • /Applications/Xcode9.1.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/Accelerate.framework/Frameworks/vImage.framework/Headers


来源:https://stackoverflow.com/questions/47267464/how-to-convert-bgra-to-rgba-in-xamarin-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!