简体   繁体   English

UIImageOrientation文档不正确

[英]UIImageOrientation documentation is incorrect

Looking through Apple's documentation for UIImageOrientation I notice that the images that go with the descriptions are incorrect. 在Apple的UIImageOrientation文档中,我发现与说明一起使用的图像不正确。

https://developer.apple.com/reference/uikit/uiimageorientation https://developer.apple.com/reference/uikit/uiimageorientation

This has been painful for me, so I'm going to leave this here, with the correct images in the answer in case others find the same. 这对我来说很痛苦,所以我将把它留在这里,并在答案中提供正确的图像,以防其他人发现相同的图像。

If people think this shouldn't be here, please comment / vote down and I'll remove. 如果人们认为不应该在这里,请发表评论/投票,然后我将其删除。

Here's how I got the correct images: 这是我获得正确图像的方式:

extension UIImage {

    var normalised: UIImage {

        if imageOrientation == .up {
            return self
        }

        var normalisedImage: UIImage

        let format = UIGraphicsImageRendererFormat.default()
        format.scale = scale
        format.opaque = true
        format.prefersExtendedRange = false
        normalisedImage = UIGraphicsImageRenderer(size: size, format: format).image { _ in
            draw(in: CGRect(origin: .zero, size: size))
        }

        return normalisedImage
    }

    func translated(to orientation: UIImageOrientation) -> UIImage {
        guard let cgImage = cgImage else {

            return self
        }

        return UIImage(cgImage: cgImage, scale: 1, orientation: orientation).normalised
    }
}

Then using this image as the "base" 然后将此图片用作“基础”

在此处输入图片说明

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM