Why does this transformation fails to result in the same image data?
let path = Bundle(for: type(of: self)).url(forResource: "Image", withExtension: "jpg")
inputData = try! Data(contentsOf: path!)
let testImage = UIImage(data: inputData)
let testImageData = UIImageJPEGRepresentation(testImage!, 1.0)
expect(testImageData).to(equal(inputData))
From what I understand UIImageJPEGRepresentation
and UIImagePNGRepresentation
can strip the image of meta data. Is that the reason?
UIImageJPEGRepresentation
function but withUIImage
construction. It is hard to reason about a content ofUIImage
internals one thing to mention that it most likely to unpack jpeg to some bitmap format. So, converting this back to jpeg doesn't guarantee to have same data. Btw, what you'd like to test with this code? – ilya Nov 23 '18 at 12:06UIImage
object. In general there is no guarantee of having the same data with such chain of conversions. – ilya Nov 23 '18 at 12:12