Skip to content

Migrate image tinting to UIGraphicsImageRenderer #3893

@1ec5

Description

@1ec5

#2873 introduced a UIImage.tint(_:) method that uses the dated UIGraphicsBeginImageContextWithOptions(_:_:_:), UIGraphicsGetImageFromCurrentImageContext(), and UIGraphicsEndImageContext() functions. We should migrate this method to the more readable and less error-prone UIGraphicsImageRenderer API.

UIGraphicsBeginImageContextWithOptions(imageSize, false, imageScale)
defer { UIGraphicsEndImageContext() }
UIColor.black.setFill()
UIRectFill(contextBounds)
draw(at: .zero)
guard let imageOverBlack = UIGraphicsGetImageFromCurrentImageContext() else { return self }
tintColor.setFill()
UIRectFill(contextBounds)
imageOverBlack.draw(at: .zero, blendMode: .multiply, alpha: 1)
draw(at: .zero, blendMode: .destinationIn, alpha: 1)
guard let finalImage = UIGraphicsGetImageFromCurrentImageContext() else { return self }

/ref #2928 (comment)
/cc @S2Ler

Metadata

Metadata

Assignees

No one assigned

    Labels

    UIWork related to visual components, Android Auto, Camera, 3D, voice, etc.jira-sync-completeop-exRefactoring, Tech Debt or any other operational excellence work.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions