Ios CametLayer可绘制纹理在某些设备上很奇怪
我使用下面的代码从金属层获取并附加一个像素缓冲区。在某些非特定设备上,输出如下所示,可绘制纹理pixelFormat为Ios CametLayer可绘制纹理在某些设备上很奇怪,ios,metal,Ios,Metal,我使用下面的代码从金属层获取并附加一个像素缓冲区。在某些非特定设备上,输出如下所示,可绘制纹理pixelFormat为。无效 static func make(with currentDrawable: CAMetalDrawable, usingBuffer pool: CVPixelBufferPool) -> (CVPixelBuffer?, UIImage) { let destinationTexture = currentDrawable.texture
。无效
static func make(with currentDrawable: CAMetalDrawable, usingBuffer pool: CVPixelBufferPool) -> (CVPixelBuffer?, UIImage) {
let destinationTexture = currentDrawable.texture
var pixelBuffer: CVPixelBuffer?
_ = CVPixelBufferPoolCreatePixelBuffer(kCFAllocatorDefault, pool, &pixelBuffer)
if let pixelBuffer = pixelBuffer {
CVPixelBufferLockBaseAddress(pixelBuffer, CVPixelBufferLockFlags.init(rawValue: 0))
let region = MTLRegionMake2D(0, 0, Int(currentDrawable.layer.drawableSize.width), Int(currentDrawable.layer.drawableSize.height))
let bytesPerRow = CVPixelBufferGetBytesPerRow(pixelBuffer)
let tempBuffer = CVPixelBufferGetBaseAddress(pixelBuffer)
destinationTexture.getBytes(tempBuffer!, bytesPerRow: Int(bytesPerRow), from: region, mipmapLevel: 0)
let image = imageFromCVPixelBuffer(buffer: pixelBuffer)
CVPixelBufferUnlockBaseAddress(pixelBuffer, CVPixelBufferLockFlags.init(rawValue: 0))
return (pixelBuffer, image)
}
return (nil, UIImage())
}
static func imageFromCVPixelBuffer(buffer: CVPixelBuffer) -> UIImage {
let ciimage = CIImage(cvPixelBuffer: buffer)
let cgimgage = context.createCGImage(ciimage, from: CGRect(x: 0, y: 0, width: CVPixelBufferGetWidth(buffer), height: CVPixelBufferGetHeight(buffer)))
let uiimage = UIImage(cgImage: cgimgage!)
return uiimage
}
有人知道为什么会发生这种情况以及如何预防吗
这里还可以找到一些来自经历过这种情况的人的反馈:CVPixelBuffer的
imageFromCVPixelBuffer
是如何工作的?@rhytricFistman添加到question@RhythmicFistman这里是一个包含这个问题的开源项目的链接。这个问题取决于它吗?我没有。它也可能发生在scenekit上。