我到處搜索並找到了一些關於如何掩蓋圖像的例子,但它們都不適合我...我在iOS9上運行並使用Swift2.0在Swift 2.0中掩蓋圖像
現在這就是我:
class func maskImage(background: UIImage, withMask mask: UIImage) -> UIImage {
let bitmapInfo = CGBitmapInfo(rawValue: CGImageAlphaInfo.PremultipliedLast.rawValue).rawValue
let colorSpace = CGColorSpaceCreateDeviceRGB()!
let context = CGBitmapContextCreate(nil, CGImageGetWidth(mask.CGImage), CGImageGetHeight(mask.CGImage), 8, 0, colorSpace, bitmapInfo)
CGContextDrawImage(context, CGRectMake(0, 0, mask.size.width * mask.scale, mask.size.height * mask.scale), mask.CGImage)
let maskRef: CGImageRef = CGBitmapContextCreateImage(context)!
let masked: CGImageRef = CGImageCreateWithMask(background.CGImage, maskRef)!
let icon: UIImage = UIImage(CGImage: masked, scale: mask.scale, orientation: mask.imageOrientation)
return icon
}
我傳遞兩個PNG文件並得到錯誤:EXC_BAD_INSTRUCTION在哪裏我初始化屏蔽線。我沒有足夠的代表發佈圖片。
我可能錯過了一些超級簡單的東西,但會愛上你的幫助。謝謝!
你只是想改變圖像的顏色爲純色? – aasatt
我正在嘗試合併一個配置文件圖像(90x90)並用菱形框掩蓋它。 –