Reputation: 21
The same app generates different images from one video on emulator and on a real device
assetImageGenerator.appliesPreferredTrackTransform = true
assetImageGenerator.requestedTimeToleranceBefore = CMTime.zero
assetImageGenerator.requestedTimeToleranceAfter = CMTime.zero
assetImageGenerator.generateCGImagesAsynchronously(forTimes: times){rTime,image,aTime,_,error in
savePNG(image, url)
}
....
static func savePNG(_ image: CGImage, url: CFURL, properties: CFDictionary? = nil) {
guard let myImageDest = CGImageDestinationCreateWithURL(url, kUTTypePNG, 1, nil) else { return }
CGImageDestinationAddImage(myImageDest, image, properties)
CGImageDestinationFinalize(myImageDest)
}
Here is the python code that I use to compare images
The result CGImage has different BitmapInfo. I'm trying to change simulator result to bitmapinfo like the device result.
let colorSpace = CGColorSpaceCreateDeviceRGB()
let bitmapInfo = CGBitmapInfo(rawValue: CGBitmapInfo.byteOrder32Little.rawValue | CGImageAlphaInfo.premultipliedFirst.rawValue)
let ctx = CGContext(data: nil,
width: image.width,
height: image.height,
bitsPerComponent: image.bitsPerComponent,
bytesPerRow: image.bytesPerRow,
space: image.colorSpace ?? colorSpace,
bitmapInfo: bitmapInfo.rawValue)!
ctx.draw(image, in: bounds)
let resultCGimage = ctx.makeImage()
But it doesn't affect
Upvotes: 1
Views: 65