How to obtain a CGImageRef from the content of an UIView?

Вот один прием, который вы увидите в разных местах:

status=`ps -efww | grep -w "[a]bc.sh" | awk -vpid=$ '$2 != pid { print $2 }'`
if [ ! -z "$status" ]; then
    echo "[`date`] : abc.sh : Process is already running"
    exit 1;
fi

Скобки вокруг [a] (или выберите другую букву) не позволяют grep найти себя. Это делает бит grep -v grep ненужным. Я также удалил grep -v $ и исправил часть awk, чтобы выполнить то же самое.

8
задан Peter Hosey 23 September 2010 в 17:05
поделиться

1 ответ

Swift 5

extension UIView {
    var cgImage: CGImage? {
        guard bounds.size.width > 0 && bounds.size.height > 0 else {return nil}
        UIGraphicsBeginImageContextWithOptions(bounds.size, isOpaque, contentScaleFactor)
        layer.render(in: UIGraphicsGetCurrentContext()!)
        defer {UIGraphicsEndImageContext()}
        return UIGraphicsGetImageFromCurrentImageContext()!.cgImage!
    }
}
0
ответ дан 5 December 2019 в 12:53
поделиться
Другие вопросы по тегам:

Похожие вопросы: