This file contains 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
let image = UIImage(named: "images.jpeg")! | |
let degrees: Double = 90 | |
let rads = CGFloat(M_PI * degrees / 180) | |
UIGraphicsBeginImageContext(CGSizeMake(image.size.height, image.size.width)) | |
let ctx = UIGraphicsGetCurrentContext() | |
CGContextTranslateCTM(ctx, image.size.height/2, image.size.width/2) | |
CGContextRotateCTM(ctx, rads) | |
CGContextScaleCTM(ctx, 1.0, -1.0) |
This file contains 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
let image = UIImage(named: "images.jpeg")! | |
UIGraphicsBeginImageContextWithOptions(image.size, false, 1.0) | |
var context = UIGraphicsGetCurrentContext() | |
//move and invert canvas by scaling | |
CGContextTranslateCTM(context, 0, image.size.height) | |
CGContextScaleCTM(context, 1, -1) | |
image.drawInRect(CGRect(x: 0, y: 0, width: image.size.width, height: image.size.height)) |
This file contains 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
func grayScale() -> UIImage { | |
let width = self.size.width | |
let height = self.size.height | |
let imageRect:CGRect = CGRectMake(0, 0, width, height) | |
let colorSpace = CGColorSpaceCreateDeviceGray() | |
let bitmapInfo = CGBitmapInfo(rawValue: CGImageAlphaInfo.None.rawValue) | |
let context = CGBitmapContextCreate(nil, Int(width), Int(height), 8, 0, colorSpace, bitmapInfo.rawValue) | |
CGContextDrawImage(context, imageRect, self.CGImage) |
This file contains 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
func fixOrientation() -> UIImage { | |
// No-op if the orientation is already correct | |
if ( self.imageOrientation == UIImageOrientation.Up ) { | |
return self; | |
} | |
// We need to calculate the proper transformation to make the image upright. | |
// We do it in 2 steps: Rotate if Left/Right/Down, and then flip if Mirrored. | |
var transform: CGAffineTransform = CGAffineTransformIdentity |
This file contains 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
class ViewController: UIViewController { | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
// Do any additional setup after loading the view, typically from a nib. | |
// Force view follow specific orientation | |
let value = UIInterfaceOrientation.LandscapeRight.rawValue | |
UIDevice.currentDevice().setValue(value, forKey: "orientation") | |
} |
This file contains 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
func cgImageFromSampleBuffer(sampleBuffer: CMSampleBuffer) -> CGImage { | |
let pixelBuffer : CVPixelBufferRef = CMSampleBufferGetImageBuffer(sampleBuffer)! | |
let ciImage = CIImage(CVPixelBuffer: pixelBuffer) | |
let context: CIContext = CIContext(options: nil) | |
let rect = CGRectMake(0, 0, CGFloat(CVPixelBufferGetWidth(pixelBuffer)), CGFloat(CVPixelBufferGetHeight(pixelBuffer))) | |
let cgImage = context.createCGImage(ciImage, fromRect: rect) | |
return cgImage | |
} |
This file contains 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
func ciImageFromSampleBuffer(sampleBuffer: CMSampleBuffer) -> CIImage { | |
let pixelBuffer : CVPixelBufferRef = CMSampleBufferGetImageBuffer(sampleBuffer)! | |
let attachments : CFDictionaryRef = CMCopyDictionaryOfAttachments(kCFAllocatorDefault, pixelBuffer, CMAttachmentMode( kCMAttachmentMode_ShouldPropagate))! | |
let ciImage = CIImage(CVPixelBuffer: pixelBuffer, options: attachments as? [String : AnyObject]) | |
return ciImage | |
} |
This file contains 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
class AWSS3Util: NSObject { | |
class func uploadFileAtURL(fileURL: NSURL, | |
fileName: String, | |
progessCallBack: AWSNetworkingUploadProgressBlock?, | |
responseCallBack: (error: NSError?) -> Void ) { | |
let uploadRequest = AWSS3TransferManagerUploadRequest() | |
uploadRequest.body = fileURL | |
uploadRequest.key = fileName |
This file contains 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
//http://blog.apoorvmote.com/uitapgesturerecognizer-to-switch-between-two-uiviews-in-ios-swift/ | |
var isPurpleViewShowing = false | |
@IBOutlet weak var greenView: UIView! | |
@IBOutlet weak var purpleView: UIView! | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
} |
This file contains 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 UIView { | |
func removeAllConstraints() { | |
var superview = self.superview | |
while superview != nil { | |
for c in superview!.constraints { | |
if c.firstItem as? UIView == self || c.secondItem as? UIView == self { | |
superview!.removeConstraint(c) | |
} | |
} | |
superview = superview!.superview |