Creating an animated GIF in Cocoa - defining frame type

后端 未结 1 1954
庸人自扰
庸人自扰 2021-02-10 20:11

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 20:50

    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)
提交回复
热议问题