title: Render a MTIImage
body: <p>Please don't judge me I'm just learning Swift.</p>
  
  <p>Recently I installed MetalPetal framework and I followed the instructions:</p>
  
  <blockquote>
    <p><a href="https://github.com/MetalPetal/MetalPetal#example-code" rel="nofollow noreferrer">https://github.com/MetalPetal/MetalPetal#example-code</a></p>
  </blockquote>
  
  <p>But I get error because of MTIContext. Maybe I have to declare something more of MetalPetal?</p>
  
  <p><strong>My Code:</strong></p>
  
  <p><img src="https://i.stack.imgur.com/xmKpY.png" alt="My Code"></p>
  
  <pre><code>import UIKit
  import MetalPetal
  import CoreGraphics
  
  class ViewController: UIViewController {
  
      @IBOutlet weak var image1: UIImageView!
      override func viewDidLoad() {
  
          super.viewDidLoad()
  
  
  
  
          weak var image: UIImage?
          image = image1.image
          var ciImage = CIImage(image: image!)
          var cgImage1 = convertCIImageToCGImage(inputImage: ciImage!)
          let imageFromCGImage = MTIImage(cgImage: cgImage1!)
  
  
          let inputImage = imageFromCGImage
          let filter = MTISaturationFilter()
          filter.saturation = 1
          filter.inputImage = inputImage
  
          let outputImage = filter.outputImage
  
  
          let context = MTIContext()
  
          do {
              try context.render(outputImage, to: pixelBuffer)
  
              var image3: CIImage? = try context.makeCIImage(from: outputImage!)
  
              //context.makeCIImage(from: image)
  
              //context.makeCGImage(from: image)
          } catch {
              print(error)
          }
  
  
  
  
  
          // Do any additional setup after loading the view, typically from a nib.
      }
  
      override func didReceiveMemoryWarning() {
          super.didReceiveMemoryWarning()
          // Dispose of any resources that can be recreated.
      }
      func convertCIImageToCGImage(inputImage: CIImage) -&gt; CGImage? {
          let context = CIContext(options: nil)
          if let cgImage = context.createCGImage(inputImage, from: inputImage.extent) {
              return cgImage
          }
          return nil
      }
  
  }
  </code></pre>
  
  <p>@YuAo</p>