Creating Gif Image Color Maps in iOS 11

你说的曾经没有我的故事 提交于 2019-12-04 02:10:01

This is a bug in iOS 11.0 and 11.1. Apple has fixed this in iOS 11.2+

I saw zip project. it's seems not "swifty".. :)

Anyway:

  • below You can find minimal code that works for iOS 11.
  • we can start from this

  • questions:

    1) what should happen for different sizes? we muse resize GIF of make a black area around original image in a new big image

    2) can you give me more details about color maps?

    3) what is all the stuff with matrixes? it seems you want to fill in black? this is not the smart and quicker approach. I will use Apple functions to scale up/fill background.

I can help You once You have kindly answered.

class ViewController: UIViewController {

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.

    if let image = UIImage(named: "image1"){
        createGIFFrom(image: image)
    }
}

final func localPath()->URL{
    let tempPath = NSTemporaryDirectory()
    let url = URL.init(fileURLWithPath: tempPath)
    return url.appendingPathComponent("test.gif")
}


private final func createGIFFrom(image: UIImage){
    let fileURL = self.localPath()
    let type: CFString = kUTTypeGIF// kUTTypePNG
    // from apple code:
    //https://developer.apple.com/library/content/technotes/tn2313/_index.html

    guard let myImageDest = CGImageDestinationCreateWithURL(fileURL as CFURL, type, 1, nil) else{
        return
    }

    guard let imageRef = image.cgImage else{
        return
    }

    // Add an image to the image destination
    CGImageDestinationAddImage(myImageDest, imageRef, nil)
    CGImageDestinationFinalize(myImageDest)

    print("open image at: \(fileURL)")

}

}

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!