获取rawimage的像素点函数_swift – 从CGImage获取像素格式

本文介绍了如何在Swift中根据CGBitmapInfo获取像素格式,并提供了相关扩展,详细讨论了颜色空间和位序对像素数据的影响。通过示例展示了不同图像的像素成分差异。
摘要由CSDN通过智能技术生成

几年后,在测试我的生产结果后,我可以很自信地分享它们,但希望有理论知识的人能在这里更好地解释一下吗?刷新记忆的好地方:

基于此,您可以使用以下扩展:

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值