4 func resize(size:CGSize) -> CGImage? {
5 let width: Int = Int(size.width)
6 let height: Int = Int(size.height)
8 let bytesPerPixel = self.bitsPerPixel / self.bitsPerComponent
9 let destBytesPerRow = width * bytesPerPixel
11 guard let colorSpace = self.colorSpace else { return nil }
12 guard let context = CGContext(data: nil, width: width, height: height, bitsPerComponent: self.bitsPerComponent, bytesPerRow: destBytesPerRow, space: colorSpace, bitmapInfo: self.alphaInfo.rawValue) else { return nil }
14 context.interpolationQuality = .none
15 context.draw(self, in: CGRect(x: 0, y: 0, width: width, height: height))
17 return context.makeImage()