extension UIImage {
/*限制图片大小*/
func resize(width:CGFloat, height:CGFloat) -> UIImage {
let myImageSize = CGSizeMake(width, height)
UIGraphicsBeginImageContextWithOptions(myImageSize, false, 0.0)
let myImageRect = CGRectMake(0, 0, myImageSize.width, myImageSize.height)
self.drawInRect(myImageRect)
let image = UIGraphicsGetImageFromCurrentImageContext()!
UIGraphicsEndImageContext()
return image
}
/*生成纯色图片*/
class func imageColored(color: UIColor) -> UIImage! {
let rect = CGRect(x: 0, y: 0, width: 0.5, height: 0.5)
UIGraphicsBeginImageContextWithOptions(rect.size, CGColorGetAlpha(color.CGColor) == 1, 0)
let context = UIGraphicsGetCurrentContext()!
CGContextSetFillColorWithColor(context, color.CGColor)
CGContextFillRect(context, rect)
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return image
}
/* 压缩图片,最大为1M */
fu