当我尝试在XCODE 6.2中运行代码时,我收到错误消息.建议我解决方案.

在使用swift 4从UIImage裁剪透明像素后,我需要帮助来创建完美清晰的图像.
我想用删除透明颜色创建图像,所以为此我使用了下面的代码.但它会模糊图像,出现小的小方形矩形.
let imageCroppedBg = imgWithClearBackgroung!.cropAlpha()
//UIImage extension
extension UIImage {
func cropAlpha() -> UIImage {
let cgImage = self.cgImage!;
let width = cgImage.width
let height = cgImage.height
let colorSpace = CGColorSpaceCreateDeviceRGB()
let bytesPerPixel:Int = 4
let bytesPerRow = bytesPerPixel * width
let bitsPerComponent = 8
let bitmapInfo: UInt32 = CGImageAlphaInfo.premultipliedLast.rawValue | CGBitmapInfo.byteOrder32Big.rawValue
guard let context = CGContext(data: nil, width: width, height: height, bitsPerComponent: bitsPerComponent, bytesPerRow: bytesPerRow, space: colorSpace, bitmapInfo: bitmapInfo),
let ptr = context.data?.assumingMemoryBound(to: UInt8.self) else { …Run Code Online (Sandbox Code Playgroud) ios ×3
swift ×2
xcode ×2
crop ×1
ios8.3 ×1
iphone ×1
objective-c ×1
uialertview ×1
uiimage ×1
xcode6 ×1