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

Image uploading on iOS

Image uploading on iOS

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

58b40ae3b0db6cf0202a3802e9dd70fe?s=128

cockscomb

May 21, 2015
Tweet

Transcript

  1. iOSͰͷ ը૾Ξοϓϩʔυ

  2. cockscomb

  3. None
  4. iOSͰͷ ը૾Ξοϓϩʔυ

  5. ԿΛ͍·͞Β w J04ͷਐԽʹ൐ͬͯ࠷৽ͷख๏Λ঺հ͍ͨ͠ w ϕετϓϥΫςΟεͰ͢

  6. ը૾Ξοϓϩʔυͷखॱ  1IPUP-JCSBSZ͔ΒσʔλΛऔಘ  ը૾ͷՃ޻  ਖ਼͍͠޲͖ʹճస  ඞཁͳαΠζʹॖখ 

    ద੾ͳܗࣜʹѹॖ  Ξοϓϩʔυ
  7. σʔλΛऔಘ • UIImagePickerController • UIImagePickerControllerOriginalImage • UIImagePickerControllerEditedImage • AssetsLibrary •

    Photos
  8. σʔλΛऔಘ 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 }
  9. ը૾ͷՃ޻ w 6*,JU w $PSF(SBQIJDT w $PSF*NBHF

  10. ਖ਼͍͠޲͖ʹճస 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)
  11. ඞཁͳαΠζʹॖখ var image: CIImage let scale: CGFloat = 0.5 let

    lanczosResamplingFilter = CIFilter( name: "CILanczosScaleTransform", withInputParameters: [ "inputImage" : image, "inputScale" : scale, ]) image = lanczosResamplingFilter.outputImage
  12. ద੾ͳܗࣜʹѹॖ 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)
  13. Ξοϓϩʔυ w ϚϧνύʔτϦΫΤετͱ͔Ͱ w ͦΕͧΕ͕Μ͹Δ

  14. ը૾Ξοϓϩʔυͷखॱ  1IPUP-JCSBSZ͔ΒσʔλΛऔಘ  ը૾ͷՃ޻  ਖ਼͍͠޲͖ʹճస  ඞཁͳαΠζʹॖখ 

    ద੾ͳܗࣜʹѹॖ  Ξοϓϩʔυ
  15. ௥ิ w શମΛNSOperationͷαϒΫϥεͳͲͰ࡞Δͱ Α͍ w $PSF*NBHFΛ࢖͏ͱ͖ɺՄೳͳΒCIContext ͸࢖͍ճ͢ͱΑ͍

  16. iOSͰͷ ը૾Ξοϓϩʔυ