Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate image tinting to UIGraphicsImageRenderer #3893

Open
1ec5 opened this issue May 17, 2022 · 0 comments
Open

Migrate image tinting to UIGraphicsImageRenderer #3893

1ec5 opened this issue May 17, 2022 · 0 comments
Labels
jira-sync-complete op-ex Refactoring, Tech Debt or any other operational excellence work. UI Work related to visual components, Android Auto, Camera, 3D, voice, etc.

Comments

@1ec5
Copy link
Contributor

1ec5 commented May 17, 2022

#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

@1ec5 1ec5 added op-ex Refactoring, Tech Debt or any other operational excellence work. UI Work related to visual components, Android Auto, Camera, 3D, voice, etc. labels May 17, 2022
@1ec5 1ec5 changed the title Migrate image tinting to UIGraphicsImageRenderer Migrate image tinting to UIGraphicsImageRenderer May 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
jira-sync-complete op-ex Refactoring, Tech Debt or any other operational excellence work. UI Work related to visual components, Android Auto, Camera, 3D, voice, etc.
Projects
None yet
Development

No branches or pull requests

2 participants