Skip to content

Migrate image tinting to UIGraphicsImageRenderer #3893

Open
@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

Activity

added
op-exRefactoring, Tech Debt or any other operational excellence work.
UIWork related to visual components, Android Auto, Camera, 3D, voice, etc.
on May 17, 2022
changed the title [-]Migrate image tinting to UIGraphicsImageRenderer[/-] [+]Migrate image tinting to UIGraphicsImageRenderer[/+] on May 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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

        Participants

        @1ec5@truburt

        Issue actions

          Migrate image tinting to UIGraphicsImageRenderer · Issue #3893 · mapbox/mapbox-navigation-ios