Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Image uploading on iOS

Image uploading on iOS

Presented at 関西モバイルアプリ研究会 #2

cockscomb

May 21, 2015
Tweet

More Decks by cockscomb

Other Decks in Programming

Transcript

  1. σʔλΛऔಘ let asset: PHAsset var originalData: NSData? var type: UTI?

    var imageOrientation: UIImageOrientation = .Up let options = PHImageRequestOptions() options.synchronous = true options.version = .Current let imageManager = PHImageManager.defaultManager() imageManager.requestImageDataForAsset(asset, options: options) { (imageData, dataUTI, orientation, info) -> Void in originalData = imageData type = UTI(dataUTI) imageOrientation = orientation }
  2. ਖ਼͍͠޲͖ʹճస var image = CIImage(CGImage: originalImage) // See: kCGImagePropertyOrientation var

    orientationValue: Int32 = 1 switch orientation { case .Up: break case .Down: orientationValue = 3 case .Left: orientationValue = 8 case .Right: orientationValue = 6 ... } image = image.imageByApplyingOrientation(orientationValue)
  3. ඞཁͳαΠζʹॖখ var image: CIImage let scale: CGFloat = 0.5 let

    lanczosResamplingFilter = CIFilter( name: "CILanczosScaleTransform", withInputParameters: [ "inputImage" : image, "inputScale" : scale, ]) image = lanczosResamplingFilter.outputImage
  4. ద੾ͳܗࣜʹѹॖ let context = CIContext(options: [:]) let scaledImage = context.createCGImage(image,

    fromRect: image.extent()) let processedData = NSMutableData() let destination = CGImageDestinationCreateWithData( processedData, type.UTIString, 1, nil) CGImageDestinationAddImage(destination, scaledImage, [ kCGImageDestinationLossyCompressionQuality as String : 0.8, ] as [ String : AnyObject ]) CGImageDestinationFinalize(destination)