Creating an animated GIF in Cocoa - defining frame type

后端 未结 1 482
半阙折子戏
半阙折子戏 2021-02-10 20:33

I\'ve been able to adapt some code found on SO to produce an animated GIF from the \"screenshots\" of my view, but the results are unpredictable. GIF frames are sometimes full i

相关标签:
1条回答
  • 2021-02-10 21:01

    I read your code. Please double check the "allImages" while you are creating the CGImageDestinationRef, and the "[images count]".

    the follow test code works fine:

    NSDictionary *prep = [NSDictionary dictionaryWithObject:[NSDictionary dictionaryWithObject:[NSNumber numberWithFloat:0.2f] forKey:(NSString *) kCGImagePropertyGIFDelayTime] forKey:(NSString *) kCGImagePropertyGIFDictionary];
    
    CGImageDestinationRef dst = CGImageDestinationCreateWithURL((__bridge CFURLRef)(fileURL), kUTTypeGIF, [filesArray count], nil);
    
    for (int i=0;i<[filesArray count];i++)
    {
        //load anImage from array
        ...
    
        CGImageRef imageRef=[anImage CGImageForProposedRect:nil context:nil hints:nil];
        CGImageDestinationAddImage(dst, imageRef,(__bridge CFDictionaryRef)(prep));
    
    }
    
    bool fileSave = CGImageDestinationFinalize(dst);
    CFRelease(dst);
    
    0 讨论(0)
提交回复
热议问题