iOS GIF合成有透明通道图片重叠问题

来源:互联网 发布:财神软件 编辑:程序博客网 时间:2024/05/17 06:00

iOS GIF合成有透明通道图片重叠问题

项目中需要用到合成gif, 如果图片含有透明通道, 则会出现重叠现象, 设置

kCGImagePropertyGIFHasGlobalColorMap


为true即可解决


下面是设置的代码, 


            NSMutableDictionary *gifProperty = [NSMutableDictionarydictionary];

            [gifProperty setObject:[NSNumbernumberWithFloat:frame.frame_delay]forKey:(__bridge id)kCGImagePropertyGIFDelayTime];

            

            float sysVersion = [[[UIDevicecurrentDevice] systemVersion] floatValue];

            if (sysVersion >= 10.0) {

                // ios 10以下支持有问题 kCGImagePropertyGIFHasGlobalColorMap

                [gifProperty setObject:@(true)forKey:(__bridge id)kCGImagePropertyGIFHasGlobalColorMap];

            }

            NSDictionary *frameProperties =@{ (__bridge id)kCGImagePropertyGIFDictionary: gifProperty};

            CGImageRef ref = [framegetImageRef];

            CGImageDestinationAddImage(destination, ref, (CFDictionaryRef)frameProperties);