Creating Gif Image Color Maps in iOS 11

后端 未结 2 2419
说谎
说谎 2021-02-20 18:17

I recently was having an issue when creating a Gif where if it got too big colors went missing. However thanks to help from SO someone was able to help me find a work around and

相关标签:
2条回答
  • 2021-02-20 18:34

    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)")
    
    }
    

    }

    0 讨论(0)
  • 2021-02-20 18:36

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

    0 讨论(0)
提交回复
热议问题