Skip to content

Instantly share code, notes, and snippets.

View haikieu's full-sized avatar

Hai K haikieu

View GitHub Profile
@haikieu
haikieu / imageToPixelBuffer.swift
Created May 31, 2020 08:20 — forked from omarojo/imageToPixelBuffer.swift
Image To CVPixelBuffer in Swift
var thePixelBuffer : CVPixelBuffer?
let testImage : UIImage = UIImage.init(named: "twdEnds.png")!
self.thePixelBuffer = self.pixelBufferFromImage(image: testImage)
func pixelBufferFromImage(image: UIImage) -> CVPixelBuffer {
@haikieu
haikieu / resize-vi.swift
Last active March 28, 2024 04:29 — forked from darcwader/resize-vi.swift
Resize Image using vImage (Updated for Swift 5)
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()
@haikieu
haikieu / UIImageFixedOrientationExtension.swift
Last active March 27, 2018 22:35 — forked from schickling/UIImageFixedOrientationExtension.swift
Extension to fix orientation of an UIImage (Sets orientation to portrait)
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
}