[英]kCGImagePropertyGIFLoopCount returns wrong value
我有三個作為 NSData 加載的 GIF 文件。 當我使用鍵kCGImagePropertyGIFLoopCount
檢索 LoopCount 時,它返回一個錯誤的值。
對於應該無限循環的 GIF,它返回 0(正確)。
對於循環計數為 1 的 GIF,它返回 0(不正確)。
對於循環計數為 2 的 GIF,它返回 1(不正確)。
-(void)prepareGif:(NSData*)data {
CGImageSourceRef source = CGImageSourceCreateWithData((__bridge CFDataRef) data, NULL);
CFDictionaryRef properties = CGImageSourceCopyProperties(source, nil);
NSDictionary* imageProperties = (__bridge NSDictionary*) properties;
NSDictionary* gifProperty = imageProperties[(NSDictionary*) kCGImagePropertyGIFDictionary];
int loopCount = [gifProperty[(NSString*) kCGImagePropertyGIFLoopCount] intValue]; // returns 0 for LoopCount 1 and LoopCount 0 and returns 1 for LoopCount 2
我找到了答案。 該屬性在不循環時不存在(即播放計數 = 1)。
這是我的錯誤,因為gifProperty
字典返回對象而不是原始類型。 返回的 object 是一個 NSNumber,它被強制轉換為 int,默認值為0
。 我沒有檢查nil
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.