xcode - CGBitmapInfo swift 有什么新功能?

标签 xcode bitmap swift

只是尝试使用:

    var context = CGBitmapContextCreate(nil,
        self.bounds.width as UInt,
        self.bounds.height as UInt,
        8,
        nil,
        CGColorSpaceCreateDeviceRGB(),
        kCGBitmapByteOrder32Big)

但是它说 kCGBitmapByteOrder32Big 是未解析的标识符。但是我在 stackoverflow 中发现了很多这样的例子,但是对于 objectiveC。 Q: 如何初始化/获取CGBitmapInfo

正确的语法:

   var context:CGContextRef = CGBitmapContextCreate(nil,
        UInt(self.bounds.width),
        UInt(self.bounds.height),
        8,
        0,
        CGColorSpaceCreateDeviceRGB(),
        CGBitmapInfo.ByteOrder32Big)

最佳答案

在 Swift 中,这应该是 CGBitmapInfo.ByteOrder32Big。您可以将它作为 .ByteOrder32Big 传递,因为类型 CGBitmapInfo 是已知的。

通常,TypeValue 或 kTypeValue 形式的 ObjC/CoreFoundation 枚举在 Swift 中是 Type.Value。

您将 nil 作为 bytesPerRow 传递。我想你在这里的意思是 0nil 不是一回事(尽管它可能在 ObjC 中对您有用)。

关于xcode - CGBitmapInfo swift 有什么新功能?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25893098/

相关文章:

flutter - 圆形图像文件

ios - UITableViewController 单元格中的索引超出范围 - swift

ios - 将 UIDatePicker countDownTimer 默认值设置为 1 分钟

ios - "Return"关键字对于具有返回值的 swift 函数是必需的吗

xcode - cocoa 应用程序中的 OpenCV Blob 跟踪

ios - 仪器 > 分配不显示应用程序类/对象

iOS 视频无法播放(播放按钮被划掉)

ios - 推送通知未交付 quickblox

javascript - 使用javascript获取位图的像素

actionscript-3 - AS3 - 正好有 23 个空的 Alpha channel ,下面的图像停止绘制