![](/img/trans.png)
[英]Export 16Bit Grayscale Depth Image (1440x1920) - Swift iOS15.3
[英]Exporting 16 bit image with Swift in iOS
我想導出一個 16 位圖像,我有下面的代碼
let bv = malloc(width * height * 4)!
var db = vImage_Buffer(data: bv,
height: vImagePixelCount(height),
width: vImagePixelCount(width),
rowBytes: width*2)
// vImageConvert_PlanarFtoPlanar8(&sourceBuffer, &destBuffer, 1.0, 0.0, vImage_Flags(kvImageNoFlags))
vImageConvert_PlanarFtoPlanar16F(&sourceBuffer, &db, vImage_Flags(kvImageNoFlags))
let bp = bv.assumingMemoryBound(to: UInt8.self)
let p = CGDataProvider(data: CFDataCreateWithBytesNoCopy(kCFAllocatorDefault,
bp,
width * height,
kCFAllocatorDefault))!
let cgImage = CGImage(width: width,
height: height,
bitsPerComponent: 5,
bitsPerPixel: 16,
bytesPerRow: width,
space: CGColorSpace(name: CGColorSpace.linearSRGB)!,
bitmapInfo: CGBitmapInfo(rawValue: CGImageAlphaInfo.noneSkipFirst.rawValue),
provider: p,
decode: nil,
shouldInterpolate: false,
intent: .defaultIntent)!
let savePath = self.documentsPath.appendingPathComponent("camera")
let sURL = savePath.appendingPathComponent(String(format: "image.png")
if let imageDestination = CGImageDestinationCreateWithURL(smoothedSceneDepthURL as CFURL, kUTTypePNG, 1, nil) {
CGImageDestinationAddImage(imageDestination, cgImage, nil)
CGImageDestinationFinalize(imageDestination)
}
Apple 文檔說這些 bitsPerComponent 和 bitsPerPixel 的值對 iOS 來說是正確的
但我收到以下錯誤: [Unknown process name] CGImageCreate: invalid image bits/pixel or bytes/row.
我能夠以灰度導出 8 位圖像,並且可以在需要時發布參數順便說一句
如果每個像素有 16 位,那么每行將有2*width
字節:
bytesPerRow: 2 * width,
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.