static func cropImage(_ image: UIImage, withRect rect: CGRect, angle: Double) -> UIImage? {
// Creates a bitmap-based graphics context with rect size
// and makes it the current context
UIGraphicsBeginImageContext(rect.size)
// Get current graphics context
guard let context = UIGraphicsGetCurrentContext() else { return nil }
// Move context origin to rect center
context.translateBy(x: rect.width / 2, y: rect.height / 2)
// Convert angle to radian and rotate
context.rotate(by: CGFloat(angle / 180 * M_PI))
// Move context origin back (-rect.width / 2, -rect.height / 2)
// and move opposite direction of rect origin (-rect.minX, -rect.minY)
context.translateBy(x: -rect.width / 2 - rect.minX, y: -rect.height / 2 - rect.minY)
// Draw image at context origin
image.draw(at: .zero)
// Get image
let finalImage = UIGraphicsGetImageFromCurrentImageContext()
// Removes the current bitmap-based graphics context from the top of the stack
UIGraphicsEndImageContext()
// Return image
return finalImage
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有