mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2025-08-12 06:26:36 +00:00
Implement default timeline avatar. Issue #641
This commit is contained in:
@@ -1,38 +0,0 @@
|
||||
//
|
||||
// UIImage-Extensions.swift
|
||||
// NetNewsWire
|
||||
//
|
||||
// Created by Maurice Parker on 4/18/19.
|
||||
// Copyright © 2019 Ranchero Software. All rights reserved.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
|
||||
extension UIImage {
|
||||
|
||||
func maskWithColor(color: UIColor) -> UIImage? {
|
||||
|
||||
let maskImage = cgImage!
|
||||
|
||||
let width = size.width
|
||||
let height = size.height
|
||||
let bounds = CGRect(x: 0, y: 0, width: width, height: height)
|
||||
|
||||
let colorSpace = CGColorSpaceCreateDeviceRGB()
|
||||
let bitmapInfo = CGBitmapInfo(rawValue: CGImageAlphaInfo.premultipliedLast.rawValue)
|
||||
let context = CGContext(data: nil, width: Int(width), height: Int(height), bitsPerComponent: 8, bytesPerRow: 0, space: colorSpace, bitmapInfo: bitmapInfo.rawValue)!
|
||||
|
||||
context.clip(to: bounds, mask: maskImage)
|
||||
context.setFillColor(color.cgColor)
|
||||
context.fill(bounds)
|
||||
|
||||
if let cgImage = context.makeImage() {
|
||||
let coloredImage = UIImage(cgImage: cgImage)
|
||||
return coloredImage
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user