作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
通过将 CGContext 与下面的代码结合使用,我们可以从缓冲区创建图像。在这段代码中,您基本上指向内存中的起始地址,以及您将从内存中的该点获取数据以构建图像的距离。
但是如果我们有保存图像数据的变量,让我们说 imageData 作为我们从其他来源(例如本地网络中的其他设备)下载的数据类型。
let baseAddress = CVPixelBufferGetBaseAddress(imageBuffer)
let bytesPerRow = CVPixelBufferGetBytesPerRow(imageBuffer)
let colorSpace = CGColorSpaceCreateDeviceRGB()
var bitmapInfo = CGBitmapInfo.byteOrder32Little.rawValue
bitmapInfo |= CGImageAlphaInfo.premultipliedFirst.rawValue
//CGBitmapInfo(rawValue: CGImageAlphaInfo.premultipliedLast.rawValue)
let context = CGContext(data: baseAddress, width: videoWidth, height: videoHeight, bitsPerComponent: 8, bytesPerRow: bytesPerRow, space: colorSpace, bitmapInfo: bitmapInfo)!
let frameImage = context.makeImage()! // This is a CGImage
最佳答案
假设您已经有一个名为 data
的变量,它将图像数据保存为 Data
类型,那么您可以使用此变量创建图像:
变种图像= UIImage(数据:数据)
关于ios - 有没有办法在 Swift 4 中使用 CGContext 创建没有指针的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53810030/
我是一名优秀的程序员,十分优秀!