Skip to content

Instantly share code, notes, and snippets.

@tad-iizuka
Created October 2, 2017 06:27
Show Gist options
  • Save tad-iizuka/f64b5640afb3c56f0b077d1755355ce0 to your computer and use it in GitHub Desktop.
Save tad-iizuka/f64b5640afb3c56f0b077d1755355ce0 to your computer and use it in GitHub Desktop.
Crush when processing .jpegRepresentation
//
// ViewController.swift
// CoreImageDebug
//
// Created by Tadashi on 2017/10/02.
// Copyright © 2017 UBUNIFU Inc. All rights reserved.
//
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var imageView: UIImageView!
var images: [CIImage] = []
let NUM = 8
override func viewDidLoad() {
super.viewDidLoad()
for _ in 0..<NUM {
let url = URL(fileURLWithPath: Bundle.main.path(forResource: "10", ofType: "dng")!)
let f = CIFilter(imageURL: url, options:nil)
self.images.append(f!.outputImage!)
}
var image: CIImage!
let context = CIContext(options: nil)
let f = CIFilter(name: "CIOverlayBlendMode")
image = self.images[0]
let colorSpace = image.colorSpace
for i in 1..<self.images.count {
f?.setValue(image, forKey: kCIInputImageKey)
f?.setValue(self.images[i], forKey: kCIInputBackgroundImageKey)
image = f?.outputImage
}
let jpeg = context.jpegRepresentation(of: image!, colorSpace: colorSpace!, options: [:])
DispatchQueue.main.async {
self.imageView.image = UIImage.init(data: jpeg!)
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment