Why image from UIGraphicsImageRenderer used with PDFPage is faded?

138 Views Asked by At

This is how I create PDFDocument:

let document = PDFDocument()

for image in images {
    let page = PDFPage(image: image.scaledWithMaxWidthOrHeightValue(value: 425)!)!
    document.insert(page, at: document.pageCount)
}

And here is an extension for UIImage:

extension UIImage {

    func scaledWithMaxWidthOrHeightValue(value: CGFloat) -> UIImage? {
        
        let width = self.size.width
        let height = self.size.height
        
        if width <= value && height <= value {
            return self
        }
        
        let ratio = width/height
        
        var newWidth = value
        var newHeight = value
        
        if ratio > 1 {
            newWidth = min(width, value)
            newHeight = height * (newWidth/width)
        } else {
            newHeight = min(height, value)
            newWidth = width * (newHeight/height)
        }
        let renderer = UIGraphicsImageRenderer(size: CGSize(width: newWidth, height: newHeight))
        let image = renderer.image { _ in
            draw(in: CGRect(x: 0, y: 0, width: newWidth, height: newHeight))
        }
        return image
    }
}

and the result look like this (this is screenshot made by one of the users, iPadOS 16.6):

enter image description here

but definitely should be like (the same feature on my own device, also 16.6):

enter image description here

I have no idea what cause that. On my devices it doesn't exist. As user said it also happens on his iPhone 12 Pro Max with latest iOS 16.6. It is not related to system (I think) and device. So what setting in the system might be related to that issue? I have tried some Accessibility Settings to reproduce the issue, but without success. Any other ideas?

Clarification edit

This question is about to where to search the issue to reproduce the problem. So it is obvious there is no code to reproduce the issue because me (the one who asked the question) is not able to reproduce the issue.

0

There are 0 best solutions below