出于测试目的,我需要生成一个非常大的UIImage(超过15 MB)。我试过了:
private func imageWithSize(size: CGSize) -> UIImage {
let rect = CGRectMake(0, 0, size.width, size.height)
UIGraphicsBeginImageContextWithOptions(size, false, 0)
UIColor.orangeColor().setFill()
UIRectFill(rect)
let image: UIImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return image
}
但图片太小(通过调用NSData
生成的UIImageJPEGRepresentation
小于15 MB)或代码在UIGraphicsGetImageFromCurrentImageContext()
崩溃