Swift – Different pngData() sizes in different iOS in unit tests

I'm testing a rotation of an image on my Swift project using unit tests.

I'm getting different results to pngData() when I test with iOS 13.7 then when I test with iOS 11.2.

Also strange and I think it's related and also my real problem is that -

On iOS 13.7 comparing 2 images - static image and rotated image - return that they are the same data size.

On iOS 11.2 - my static image changed its data size by X AMOUNT and my rotated image changed its data size by Y AMOUNT and now they have different data sizes and my test fails.

The rotate func -

func cld_rotate(_ degree: Float) -> UIImage? {
    var newSize = CGRect(origin: CGPoint.zero, size: self.size).applying(CGAffineTransform(rotationAngle: cld_radians(from: Double(degree)))).size
    // Trim off the extremely small float value to prevent core graphics from rounding it up
    newSize.width = floor(newSize.width)
    newSize.height = floor(newSize.height)
    UIGraphicsBeginImageContextWithOptions(newSize, false, self.scale)
    let context = UIGraphicsGetCurrentContext()!
    // Move origin to middle
    context.translateBy(x: newSize.width/2, y: newSize.height/2)
    // Rotate around middle
    context.rotate(by: cld_radians(from: Double(degree)))
    // Draw the image at its center
    draw(in: CGRect(x: -self.size.width/2, y: -self.size.height/2, width: self.size.width, height: self.size.height))
    let newImage = UIGraphicsGetImageFromCurrentImageContext()
    return newImage

Any idea about why pngData() is not the same used in 2 different iOS? And why the rotated image change its data size by a different amount than the static one?

Read more here: https://stackoverflow.com/questions/64896443/swift-different-pngdata-sizes-in-different-ios-in-unit-tests

Content Attribution

This content was originally published by ozd at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: