This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var thePixelBuffer : CVPixelBuffer? | |
let testImage : UIImage = UIImage.init(named: "twdEnds.png")! | |
self.thePixelBuffer = self.pixelBufferFromImage(image: testImage) | |
func pixelBufferFromImage(image: UIImage) -> CVPixelBuffer { | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension UIImage { | |
func resize(size: CGSize) -> UIImage? { | |
guard let cgImage = self.cgImage else { return nil} | |
var format = vImage_CGImageFormat(bitsPerComponent: 8, bitsPerPixel: 32, colorSpace: nil, | |
bitmapInfo: CGBitmapInfo(rawValue: CGImageAlphaInfo.first.rawValue), | |
version: 0, decode: nil, renderingIntent: CGColorRenderingIntent.defaultIntent) | |
var sourceBuffer = vImage_Buffer() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension UIImage { | |
///UIImage instance somtimes can be at any various orientation, so this method basically converts it back to default orientation. | |
///This is picked from the original source -> https://gist.github.com/schickling/b5d86cb070130f80bb40 | |
func fixedOrientation() -> UIImage? { | |
guard imageOrientation != UIImageOrientation.up else { | |
//This is correct orientation, don't need to do anything | |
return self.copy() as? UIImage | |
} | |