几年后,在测试我的生产结果后,我可以很自信地分享它们,但希望有理论知识的人能在这里更好地解释一下吗?刷新记忆的好地方:
基于此,您可以使用以下扩展:
public enum PixelFormat
{
case abgr
case argb
case bgra
case rgba
}
extension CGBitmapInfo
{
public static var byteOrder16Host: CGBitmapInfo {
return CFByteOrderGetCurrent() == Int(CFByteOrderLittleEndian.rawValue) ? .byteOrder16Little : .byteOrder16Big
}
public static var byteOrder32Host: CGBitmapInfo {
return CFByteOrderGetCurrent() == Int(CFByteOrderLittleEndian.rawValue) ? .byteOrder32Little : .byteOrder32Big
}
}
extension CGBitmapInfo
{
public var pixelFormat: PixelFormat? {
// AlphaFirst – the alpha channel is next to the red channel,argb and bgra are both alpha first formats.
// AlphaLast – the alpha channel is next to the blue channel,rgba and abgr are both alpha last formats.
// LittleEndian – blue comes before red,bgra and abgr are little endian formats.
// Little endian ordered pixels are BGR (BGRX,XBGR,BGRA,ABGR,BGR).
// BigEndian – red comes before blue,argb and rg